Mats suggestion is one I use.

Another trick is to use count to get the total number T of items then use a 
range operator from 1 to N, in which the current tiddler will be the item 
number.

However you then need to retrieve the nth[N] item from the list.

Regards
Tones

On Tuesday, 23 March 2021 at 21:24:41 UTC+11 Mat wrote:

> You can use this to find the position of an item in a list
>
> +[allbefore<item>count[]add[1]]
>
> e.g 
>
> {{{ one two three four five +[allbefore[four]count[]add[1]]  }}} ----> 4
>
> Not sure it's the optimal solution, I just made it up.
>
> <:-)
>  
>
>
> On Tuesday, March 23, 2021 at 10:57:48 AM UTC+1 Mohamed Amin wrote:
>
>> Hi,
>>
>> Is there a way to get the position of an item in a "list field"?
>>
>> More info:
>> Recently I've discovered the "nth" filter operator 
>> <https://tiddlywiki.com/#nth%20Operator>, and one of the use case I 
>> immediately think about was to "iterate" through items in multiple related 
>> "list fields"
>>
>> Take the following example (not a real one, just to get the idea clear):
>> If a family needs to manage its friends, each family member's Tiddler 
>> will have the following fields:
>> 1- friend-names : "list field" contains ALL friends
>> 2- friendships-start-date : "list field" where the "position" of the date 
>> determine the friend's names
>> 3- friendships-meter : "list field" where the "position" of the % 
>> determine the friend's names
>>
>> Ex.
>> friend-names :         [[alex]]          [[andy]]            [[john]]    
>>          [[evan]]
>> friendships-start-date :  [[Mar2015]]   [[Dec2017]]    [[Nov2016]]    
>>  [[Feb2011]]
>> friendships-meter     [[70]]              [[30]]               [[60]]    
>>             [[90]]
>>
>> Now I can use the filter "[contain:friend-name[alex]]" to get all family 
>> members who is a friend with "alex".
>> And if I know the <<position>> of "alex" in the "friend-names" field, I 
>> can get the rest of the data corresponding to it for the currentTiddler 
>> using a filter like:
>> "[all[current]get[friendships-meter]enlist-input[]nth<position>]" 
>>
>> Regards
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/5bdc51a1-1ea9-4175-893a-4eac2f764ad3n%40googlegroups.com.

Reply via email to