> Using the TrashPlugin (2) macro, however, things get interesting. The
> script creates the new tiddlers (when necessary), but it tags both the
> old and the new tiddlers as Trash.

> var tags = f[i].tags;
and
> store.saveTiddler(title,title,text,config.options.txtUserName,new
> Date(),tags);

The tiddler tags are stored as an array.  Assigning an array to a
variable (e.g., var tags=...) doesn't actually copy the array data...
it just creates a second *reference* to the *same* array data.  Thus,
when you write:
   var tags = f[i].tags;
and then call
   store.saveTiddler(...,tags,...),
the TWCore creates the new tiddler as intended, but stores the
*reference* to the tags from the original tiddler.  This has the very
odd side-effect that, whenever you change the tags in one tiddler, the
tags in the other tiddler are also "magically" changed as well, since
there is only one actual object, shared between the two tiddlers!

In order to properly replicate a tiddler's tags, you need to "clone"
the tags array from the existing tiddler.  You can use the following
line as a quick way to do this:
   var tags = f[i].tags.slice(0);
The .slice(...) method is normally used to return a *copy* of a
portion an array starting at the specified index.  Using an index of 0
returns a copy of the entire array.

enjoy,
-e


-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To post to this group, send email to tiddlywiki@googlegroups.com.
To unsubscribe from this group, send email to 
tiddlywiki+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/tiddlywiki?hl=en.

Reply via email to