How to get a record index of a named property from a data tiddler?

94 views
Skip to first unread message

oleghbond

unread,
Feb 7, 2018, 4:18:26 AM2/7/18
to TiddlyWiki
Dear All,

I've encountered an issue which I need to resolve, namely: How to get a record index of a named property from a data tiddler?

Say, I've got the following set of records in a data tiddler:

{"oct":31,"nov":30,"dec":31}

As one can see the number index value of  the named property, say, "nov" is 2.

But how can I get this number index using a macros of a plugin?

I feel that it should be somehow simply, but I've no idea how.

I would be grateful for your help.

Olegh

BurningTreeC

unread,
Feb 7, 2018, 6:21:48 AM2/7/18
to TiddlyWiki
Hi @oleghbond,

say your data tiddler is called "datatiddler":

<$list filter="[[datatiddler]getindex[nov]]"> <<currentTiddler>> </$list>

 gives you "30" as result

you can do it in different ways. look at https://tiddlywiki.com/#getindex%20Operator

BurningTreeC

BurningTreeC

unread,
Feb 7, 2018, 6:22:46 AM2/7/18
to TiddlyWiki
or easy: {{datatiddler##nov}}

oleghbond

unread,
Feb 7, 2018, 12:09:30 PM2/7/18
to TiddlyWiki
Thank you very much,

I would like to clarify a bit the misinterpreting of my request.

What you suggest returns the value of the array under char index "nov", which is - 30. Whereas I looked for a method for returning the number index of the char index "nov", which is - 2, just because it is the second element of the array.

Any idea?

середа, 7 лютого 2018 р. 13:21:48 UTC+2 користувач BurningTreeC написав:

BurningTreeC

unread,
Feb 7, 2018, 1:15:40 PM2/7/18
to TiddlyWiki
Hi olegh, sorry I got it wrong.

That's more complex...


could this work for you?

<$set name="indexName" value="nov">

<$set name="indexes" filter="[[datatiddler]indexes[]]">
<$set name="length" filter="[enlist<indexes>] +[count[]]">
<$list filter="1 2 3 4 5 6 7 8 9 10 +[limit<length>]" variable="index">

<$list filter="[enlist<indexes>nth<index>regexp<indexName>]">

<<index>>

</$list>
</$list>
</$set>
</$set>

</$set>

BurningTreeC

unread,
Feb 7, 2018, 1:17:26 PM2/7/18
to TiddlyWiki
instead of the 1 2 3 4 5.... I normally use a tiddler that holds all integers from 1 to x in its list field and use the filter [list[integernumberstiddler]limit<length>]] variable="index"


BurningTreeC

unread,
Feb 7, 2018, 1:20:16 PM2/7/18
to TiddlyWiki
at last I think this would be better:

\define getTheIndex()
<$list filter="[enlist[$(indexes)$]nth[$(index)$]regexp[^$(indexName)$]]">

<<index>>

</$list>
\end


<$set name="indexName" value="nov">

<$set name="indexes" filter="[[datatiddler]indexes[]]">
<$set name="length" filter="[enlist<indexes>] +[count[]]">
<$list filter="1 2 3 4 5 6 7 8 9 10 +[limit<length>]" variable="index">

<<getTheIndex>>

</$list>
</$set>
</$set>

</$set>

BurningTreeC

unread,
Feb 7, 2018, 1:23:46 PM2/7/18
to TiddlyWiki
... and I see I must add a reverse[] to the list: <$list filter="1 2 3 4 5 6 7 8 9 10 +[limit<length>reverse[]]" variable="index">

Mark S.

unread,
Feb 7, 2018, 6:22:33 PM2/7/18
to TiddlyWiki
If you're just dealing with the months of the year, then the other easy possibility is to make a second data tiddler:

{"oct":1,"nov":2,"dec":3}

-- Mark
Reply all
Reply to author
Forward
0 new messages