Hello community,
today I was playing around with adding items from a JSON tiddler to the the SelectWidget.
Everything is fine, but I’d like to show a default entry in the list, too. I think this could be done with the prepend-Operator, but I don’t know where it should be inserted (like … prepend[Which item?] …)
Data Tiddler DatJSON-1:
{
"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": "Ruler",
"Details": "20cm, transparent",
"Price": 2.50
}
}
Tiddler:
<$list filter="[{!!ItemName}length[]compare:integer:gt[0]then[]]" emptyMessage="Please select item!" /><br>
<$let JSONdata={{{[{DatJSON-1}]}}} >
<$select tiddler=<<currentTiddler>> field="ItemName" >
<$list filter="[<JSONdata>jsonindexes[]]" counter="cntr">
<$set name="JSONind" filter="[<cntr>subtract[1]]">
<$let ItemName={{{[<JSONdata>jsonget<JSONind>,[Name]]}}} >
<$set name="ItemDetails" filter="[<JSONdata>jsonget<JSONind>,[Details]]" >
<$set name="ItemPrice" filter="[<JSONdata>jsonget<JSONind>,[Price]]" >
<!-- remove items without a price -->
<$let SelectString="<<ItemName>>" >
<$list filter="[<ItemPrice>match[]]" emptyMessage="<option><<SelectString>></option>" />
</$let>
</$set>
</$set>
</$let>
</$set>
</$list>
</$select>
</$let>
Thank you in advance for your help.