Tony

I'm not sure if I am understanding your suggestion correctly - do you mean 
something like this?:

<$edit-text tiddler="$:/state/enter-text" />

<$button>
<$action-setfield $tiddler=myData $index="Key Number" $value={{{ 
[{myData##Key Number}add[1]] }}} />
<$wikify name=title-value text="<<currentTiddler>> [{{myData##Key 
Number}}]/Title" >
...
<$action-setfield $tiddler=myData $index=<<title-value>> $value=<
<currentTiddler>>/>
...
</$button>

Which gives the example result:

{
    "Key Number": 3,
    "json test [1]": {
        "Title": "json test",
        "Text": "Here is some text.",
        "Date": "21:14, 14th November 2019"
    },
    "json test [2]": {
        "Title": "json test",
        "Text": "Blah",
        "Date": "21:14, 14th November 2019"
    }
}




On Wednesday, November 13, 2019 at 11:32:54 PM UTC, TonyM wrote:
>
> Mark perhaps each time you add a tiddler to the data tiddler you increment 
> a key number and use it as the key, even in a field on the data tiddler
>
> If you delete a tiddler it will just be a missing key.
>
> If you use a button to add new tiddlers you can make use of the button to 
> trigger an event to add one with the current operators (use triple curly 
> braces) to the key/index number and set the key number field to the new 
> value.
>
> Tony
>
> On Thursday, November 14, 2019 at 7:31:18 AM UTC+11, Mark S. wrote:
>>
>> Joshua's site says that the improved "indexes" filter will return all 
>> paths. So
>>
>> IF you have the same number of entries for each nested group, then you 
>> can divide by that number and add one to get the next number in the 
>> sequence:
>>
>> <$list filter="[[myData]indexes[]count[]divide[2]add[1]]" 
>> variable="nextnum">
>> ... do stuff
>> </$list>
>>
>> This example assumes 2 items per group.
>>
>> The problem with this approach is that you might, at some time, delete an 
>> entry. So this approach only works if you never delete entries.
>>
>> A more advanced approach would require you to add a "number" field to 
>> each nested group. If you had such an index, then you could write
>> a macro that would run through the entries, find the highest value and 
>> add one.
>>
>> hth
>>
>> On Wednesday, November 13, 2019 at 11:51:24 AM UTC-8, si wrote:
>>
>>> Thanks for your help, that does the trick.
>>>
>>> In order to get a new numerical value for each level every time I press 
>>> the button I have used the MathyThing 
>>> <http://inmysocks.tiddlyspot.com/#MathyThing%20-%20action-increment%20Widget>
>>>  
>>> plugin to increment the number in a field called "number". It's a little 
>>> tenuous though because it will be easy in my use case to accidentally 
>>> overwrite this number.
>>>
>>> Do you know of a better way to this? e.g. a way to count the number of 
>>> bottom level entries in the JSONTiddler and add 1 or something?
>>>
>>> I've attached an example of what I have done.
>>>
>>> <$edit-text tiddler="$:/state/enter-text"/>
>>>
>>> <$button>
>>> <$wikify name=title-value text="<<currentTiddler>> [{{!!number}}]/Title" 
>>> >
>>> <$wikify name=text-value text="<<currentTiddler>> [{{!!number}}]/Text" >
>>> <$wikify name=date-value text="<<currentTiddler>> [{{!!number}}]/Date" >
>>> <$action-increment $tiddler=<<currentTiddler>> $field=number 
>>> $initial="0" $increment="1"/>
>>> <$action-setfield $tiddler=myData $index=<<title-value>> 
>>> $value=<<currentTiddler>>/>
>>> <$action-setfield $tiddler=myData $index=<<text-value>> 
>>> $value={{$:/state/enter-text}}/>
>>> <$action-setfield $tiddler=myData $index=<<date-value>> $value=<<now>>/>
>>> </$wikify>
>>> </$wikify>
>>> </$wikify>
>>> Save
>>> </$button>
>>>
>>> Thanks again for your help.
>>>
>>> On Sunday, November 10, 2019 at 10:24:34 PM UTC, Mark S. wrote:
>>>>
>>>> Since you're writing to the same indexes on the same tiddler, it 
>>>> overwrites them.
>>>>
>>>> There's no tools in TW for handling nested data tidders, but you can use
>>>>
>>>> Joshua Fontany's JSON Mangler:
>>>>
>>>> https://joshuafontany.github.io/TW5-JsonMangler/
>>>>
>>>> Then you can make $index=level1/Title, $index=level2/Title, etc. and 
>>>> create nested data tiddlers.
>>>>
>>>> Good luck!
>>>>
>>>>

-- 
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 tiddlywiki+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/b949ea5c-4876-4327-900a-84782ee754b0%40googlegroups.com.

Reply via email to