Filter op to access non-specific field values?

55 views
Skip to first unread message

Mat

unread,
May 14, 2018, 2:35:14 AM5/14/18
to TiddlyWiki
...fields[]prefix[foo]

...but then; How do I get the values from those fields?

<:-)

Jed Carty

unread,
May 14, 2018, 6:16:14 AM5/14/18
to TiddlyWiki
I had a nice post about this written up but then my browser died.

The quick answer is that there isn't a direct way to do this nicely. We need to make it so that you can give a list of inputs and acts on a list of inputs. I think Jeremy had some ideas for how to implement this in the past but I don't know if anyone has had time to do this.

There are a few ways to work around this, they all involve nested things.

This list the values, but they are all in separate lists.
<$list filter='[[bar]fields[]prefix[foo]]' variable=fieldName>
<$list filter='[[bar]get
<fieldName>]' variable=fieldValue>
<
<fieldValue>>
</$list>
</$list>


you can get them all in the same output list but it is awkward and uses recursion so if there are too many fields it may result in a red box of javascript recursion doom.

The movingOn macro has the list of values in fieldList, it can be used as a filter. There may be a simpler way to achieve the same thing but this is the first working thing I made for it.
I think that you will need to have a lot of fields listed before there are any problems with recursion, but it is possible.

\define recursiveDoom()
<$list variable=fieldName filter='[enlist<fieldNames>first[]]' emptyMessage=<<movingOn>>>
  <$set filter='[<tiddler>has<fieldName>get<fieldName>]' name=fieldValue>
    <$set name=fieldList filter='[enlist<fieldList>append<fieldValue>]'>
      <$set name=fieldNames filter="""[enlist<fieldNames>] -[<fieldName>]""">
        <<recursiveDoom>>
      </$set>
    </$set>
  </$set>
</$list>
\end


\define movingOn()
Here you get everything as a single list<br>
<<fieldList>>
\end

<$vars prefix=foo tiddler=bar>
  <$set name=fieldList value=''>
    <$set filter='[<tiddler>fields[]prefix<prefix>]' name=fieldNames>
      <$set name=first filter='[enlist<fieldNames>first[]]'>
        <$set name=last filter='[enlist<fieldNames>last[]]'>
          <<recursiveDoom>>
        </$set>
      </$set>
    </$set>
  </$set>
</$vars>


Reply all
Reply to author
Forward
0 new messages