I have a collection called “codes” with fields “name”, “description”, and “parent” that has data such as:
“Code 1”, “Some description”,
“Code 2”, “Another description”, “Code 1”
…
etc.
I’d like to populate a Tree Widget from this Collection to that the labels in the tree are “name” and “Code 2” would be hierarchically under “Code 1”? Is this possible? How?
Hi @Researchware, thanks for the post. I’ve asked around regarding your question and my understanding is that it is possible, but you would have to code it manually. For example:
local tData
put datastoreGetDataOfCollection( \
true, \
true, \
"codes") \
into tData
local tStructuredData
repeat for each element tRecord in tData
if tRecord["parent"] is not empty then
put tRecord["description"] into
tStructuredData[tRecord["parent"]][tRecord["name"]]
else
put tRecord["description"] into tStructuredData[tRecord["name"]]
end if
end repeat
set the arrayData of widget <treeview> to tStructuredData
However, this only works if there are no multiply-nested records. If there are, then you probably have to keep track of the parent chains.
Thank you. The piece I was missing was the function “datastoreGetDataOfCollection” with no Dictionary (there probably is one I just can’t find or missed the posts about), coding much of anything is very hard. Is there any thing where I can see what all the parameters are for this finction or look up other datastore functions?
Documentation can be found here: https://docs.livecode.com/docs/LiveCode%20Script/Functions/ArrayToJSON
Unfortunately I don’t think the specific function and a lot of the datastore stuff have been added to the documentation yet though. I’ll ask the development team for some more information.
Thank you. I was aware of the web documentation, but not aware that the LC Create widgets had been added to it. I must have missed that announcement OR just was not checking the web dictionary often enough. In my specific case, I was still stuck by not having any of the Datastore commands/functions/properties/messages documented.