[TW5] Need help with manipulating data within dictionary entries

77 views
Skip to first unread message

Matabele

unread,
Jan 7, 2016, 12:03:22 AM1/7/16
to TiddlyWikiDev
Hi

I don't seem to understand the following functions:
-- getTiddlerData()
-- setTiddlerData()
-- extractTiddlerDataItem()

I am trying to:
-- extract an entry from a data index
-- convert this data to an array
-- manipulate the array
-- then save the modified array back to the data index.

What are the parameters, and parameter types for these functions?

regards

Matabele

unread,
Jan 7, 2016, 12:21:25 AM1/7/16
to TiddlyWikiDev
Hi

Perhaps I was not clear -- I wish to first load the entire tiddler:
tiddler = this.wiki.getTiddler(this.myTitle);
-- then manipulate the data within the variable 'tiddler'
-- then write back the variable 'tiddler', including modification fields etc:
this.wiki.addTiddler(new $tw.Tiddler(this.wiki.getCreationFields(), modifiedText, this.wiki.getModificationFields()));

regards

Eric Shulman

unread,
Jan 7, 2016, 12:27:13 AM1/7/16
to TiddlyWikiDev
On Wednesday, January 6, 2016 at 9:03:22 PM UTC-8, Matabele wrote:
I don't seem to understand the following functions:
-- getTiddlerData()
-- setTiddlerData()
-- extractTiddlerDataItem()

I am trying to:
-- extract an entry from a data index
-- convert this data to an array
-- manipulate the array
-- then save the modified array back to the data index.

Here's what I use:
var data = this.wiki.getTiddlerData("TiddlerTitle",{});
var val = data["index_name"];
// ... your code here.... modify 'val'...
data
["index_name"] = val;
this.wiki.setTiddlerData("TiddlerTitle",data);

The 2nd param in getTiddlerData is a fallback data object (usually empty), that is used if the specified tiddler is missing.  The object property name/value pairs correspond to the index/value pairs stored in the DataTiddler.  To add an index to a tiddler, just assign a value into the data array, e.g.,
data["some_new_index_name" = somevalue;

To remove an index from a DataTiddler, set it's value to "undefined" (no quotes).
data["some_new_index_name" = undefined;

When the data object is written back to the tiddler, the entire text content of the tiddler is overwritten with the name/value pairs from the modified object, effectively adding/removing/updating all the individual indices at once.

enjoy,
-e

Eric Shulman

unread,
Jan 7, 2016, 12:29:15 AM1/7/16
to TiddlyWikiDev
errata: previous post was missing close paren "]" in this code:
data["some_new_index_name"] = somevalue;

-e
 

Matabele

unread,
Jan 7, 2016, 12:35:29 AM1/7/16
to TiddlyWikiDev
Hi Eric

Many thanks for your prompt response :-) Will try this and see how it works for me.

regards

Matabele

unread,
Jan 7, 2016, 4:35:45 AM1/7/16
to TiddlyWikiDev
Hi Eric

Success!! Thanks again for your contribution.

regards

On Thursday, 7 January 2016 07:27:13 UTC+2, Eric Shulman wrote
Reply all
Reply to author
Forward
0 new messages