Hello,
I’m still playing around with JSON tiddlers:
Example1-JSON
{
"0": {
"Name": "Fountain Pen",
"Details": "Green, metallic",
"Price": 10
},
"1": {
"Name": "Pencil",
"Details": "No.2",
"Price": 1.50
},
"2": {
"Name": "Ballpoint Pen",
"Details": "red",
"Price": 2
},
"3": {
"Name": "Eraser",
"Details": "Soft, blue",
"Price": 2
},
"4": {
"Name": "Ruler1",
"Details": "20cm, transparent",
"Price": 2.50
},
"5": {
"Name": "Ruler2",
"Details": "10cm, wooden",
"Price": 0
},
"6": {
"Name": "Ruler3",
"Details": "5cm, cheap plastic",
"Price": 0.50
}
}
At last I found a way to display all names in one single filter (before I used two nested ListWidgets), but I also like to sort out all items without a price.
With some trial I ended up with this filter, which works the way I like it:
<$set name="JSONdata" value={{Example1-JSON}} >
<$list filter="[<JSONdata>jsonindexes[]] :map[<JSONdata>jsonget<currentTiddler>,[Price]!match[0]then<JSONdata>jsonget<currentTiddler>,[Name]]" >
</$list>
According to the description of :map
:
Filter runs used with the :map prefix should return at least the same number of items that they are passed
What does that mean exactly? Is this only a rough guideline or do I have to expect unwanted behaviour when I use it to filter out some items?
If yes: how could I do it better?
I also like to display the details in the output. My first idea was to use another :map
-instruction (in the same filter run) to access the JSON-Details, but that doesn’t work because I cannot access the currentTiddler
of the first expression (it seems that it only refers to the last filter).
Or is there some sort of a Push/Pop-mechanism (onto a stack) available for the variables in filters?
As always, I’d be grateful for any suggestions!
Thank you in advance.