Use dataviewjs to return an array of nested child fields within YAML? #1410
-
Apologies if this is obvious and I missed it. I have a a YAML table that is very likely to expand in future:
For example, at some point I might add perlite:
Is there a function in dataviewjs that will let me count the number of entries under components dynamically? I have tried the following:
But this returns a length of 1. (I am guessing that this is because dataview flattens the children into 1 object?) It would be great if I could write a function that would return an array of the children (topsoil, manure, coir) which could then be used to process the contents of each of those entries, e.g.
returning:
In theory, such a function would enable me to write the script once and then add to the YAML components indefinitely. Workaround 1
And then duplicating that logic (and all related actions) for each entry. This means that I will need to update the script every time I update the YAML 🤔 Workaround 2 example topsoil note
resulting YAML for the calculator file
And then querying the YAML of each note referenced by
I have a system like that working for plants and plant varieties, but it feels like a lot of notes for a calculator. In addition, both the price and the ratio for each component at the time of use would be variable (I might need a ratio of 1 in one situation, and 2 in another) which means I'd have to go and change the YAML in the underlying component notes for every calculation. Workaround 3 TL;DR
Into the following array? Which would then expand to |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I have now solved this issue with Workaround 3. I would still love to know if the original idea is possible (see TL;DR in the post above) as Workaround 3 is very verbose, took most of the day to assemble and led to an explosion of notes 😀 |
Beta Was this translation helpful? Give feedback.
-
Sure, just using regular javascript.
|
Beta Was this translation helpful? Give feedback.
Sure, just using regular javascript.