Adding a new index to a JSON data tiddler

262 views
Skip to first unread message

Rob Hoelz

unread,
Nov 28, 2017, 1:30:32 PM11/28/17
to TiddlyWiki
Hi TiddlyWiki users and devs!

I'm writing a UI for a plugin, and it's meant to present the contents of a JSON data tiddler in a user-friendly way.  The JSON data is a list of lists, like so:
[
 
"Firefox Fx",
 
"FTS [[full text search]]"
]

I would like to add functionality to the UI to create a new element in the top-level list - for example, to add "GTD [[getting things done]]" after "FTS [[full text search]]".  Is there some way I can use $action-listops to do this, or will I need to write something on my own?

Thanks,
Rob

PMario

unread,
Nov 29, 2017, 10:48:44 AM11/29/17
to TiddlyWiki
Hi Rob,

If you work with data tiddlers and you want to create some UI to modify the content you'll need an index. .... Any form of index, to be able to reference the content.

eg: {{myData##01}} {{myData##02}} ...

[
  "01":
"Firefox Fx",
 
"02":"FTS [[full text search]]"
]

I'm not sure, what you want to create, but I did a series of videos some time ago, which describes in detail how I did implement it:

see: A script and todo manager workflow / UI experiment

Videos 12 and 13 + the corresponding code may be interesting for you.

have fun!
mario

Joshua Fontany

unread,
Nov 29, 2017, 1:21:29 PM11/29/17
to TiddlyWiki
If the JSON tiddler is a flat array:
[ .... ]
not
{ ... }
then zero-based numerals function fine for the index.

Button to add the content of [[$:/temp/newIndex]] to the JSON tiddler defined in {{$:/temp/newIndex!!parent}}:

<$set name="i" filter="[{$:/temp/newIndex!!parent}indexes[]count[]]">
<$button>
<$action-setfield $tiddler={{$:/temp/newIndex!!parent}} $index=<<i>> $value={{$:/temp/newIndex!!text}} />
Add Index
</$button>
</$set>
Tested on Tiddlywiki.com, works fine with both JSON tiddler types. If the Json tiddler starts empty it will be started as an object {"0":"test"}, but if it is aready setup as an array, a new index will just be appended: ["test"] -> ["test,"test"]

Best,
Joshua Fontany

Rob Hoelz

unread,
Nov 29, 2017, 5:15:09 PM11/29/17
to TiddlyWiki
Ah, exploiting the fact that the length of the array is the next index - nice trick!  Thanks, Joshua - that should work nicely.
Reply all
Reply to author
Forward
0 new messages