Adding and using new properties from JSON

My intention to is to pass in a property title and value in the nodeDataArray and access these when a specific node is (re)set as .visible = false|true

I’ve added ‘showWith’ as shown below on the last item:

"nodeDataArray": [ {"category":"Comment", "loc":"329 -1", "text":"Test Additional Params", "key":-13}, {"key":-1, "category":"Start", "loc":"175 0", "text":"Start"}, <span style="line-height: 1.4;">{"text":"Y_D1", "category":"Answer", "key":-14, "loc":"254.5 151", "focusMe":"center"}, </span> {"text":"N_D1", "category":"Answer", "key":-15, "loc":"418 168", "focusMe":"top"}, <span style="line-height: 1.4;">{"category":"Comment", "text":"Show me \nwith Y_D1", "figure":"RoundedRectangle", "key":-6, "loc":"105 174", "<b>showWith</b>":"-14"} </span>

In code I would have hoped to have access to the showWith property simply through

</span> if(node.data.showWith == theNode.data.key) { // do stuff }

but it seems the general framework doesn’t expose the parameter in this manner.


I can see that if I programatically set the value such as …



</span> <span ="apple-tab-span"="" style="white-space:pre"> </span>var data = myDiagram.model.findNodeDataForKey('-6'); <span ="apple-tab-span"="" style="white-space:pre"> </span>if (data !== null) { <span ="apple-tab-span"="" style="white-space:pre"> </span>myDiagram.model.setDataProperty(data, "showWith", "-14"); <span ="apple-tab-span"="" style="white-space:pre"> </span>}


then I can access it but I don’t want to add code if it’s possible to push this value in the nodeDataArray as I would expect.


I’ve seen some examples here where users appear to be setting ‘additional’ params in the nodeDataArray but can’t see the full run-through to accessing this as part of a node object interrogation, any assistance would be gratefully received.

Thanks
Dylan

Not sure where my syntax was incorrect but after some (seemingly) unrelated updates this is now working. Perhaps I was referring to the object but I now have this working thus:




  "nodeDataArray": [ 
{"category":"Comment", "loc":"329 -1", "text":"Kookie Brittle", "key":-13},
{"key":-1, "category":"Start", "loc":"175 0", "text":"Start"},
{"key":0, "loc":"0 90", "text":"S0"},
{"key":1, "loc":"175 100", "text":"S1"},
{"key":2, "loc":"175 190", "text":"S2"},
{"key":3, "loc":"175 270", "text":"D3", "figure":"Diamond"},
{"key":4, "loc":"79 405", "text":"S4"},
{"key":6, "loc":"289 394", "text":"D4", "figure":"Diamond"},
{"key":7, "loc":"175.5 461", "text":"YN_D4", "category":"Answer"},
{"key":8, "loc":"175 570", "text":"S8"},
{"key":-2, "category":"End", "loc":"175 640", "text":"End"},
{"key":-3, "text":"D1", "figure":"Diamond", "category":"Choice", "loc":"341 106"},
{"text":"Y_D1", "category":"Answer", "key":-14, "loc":"254.5 151", "<b>focusMe</b>":"center"}, 
{"text":"N_D1", "category":"Answer", "key":-15, "loc":"418 168", "<b>focusMe</b>":"top"}, 
{"text":"N_D3", "category":"Answer", "key":-16, "loc":"271.5 303"},
{"text":"Y_D3", "category":"Answer", "key":-17, "loc":"77 308"},
{"category":"Comment", "text":"Hide me \nwith S2", "figure":"RoundedRectangle", "key":-6, "loc":"105 174", "<b>showWith</b>":"2"} 
 ],

and is picked up without additional coding thus:

[code]

<span =“Apple-tab-span” style=“white-space:pre”> if(n.data.hasOwnProperty(‘showWith’)) {
<span =“Apple-tab-span” style=“white-space:pre”> console.log(’ yes we do!’);
<span =“Apple-tab-span” style=“white-space:pre”> if(n.data.showWith == theNode.data.key) {
<span =“Apple-tab-span” style=“white-space:pre”> console.log(’ we have a value and a match…’);
[/code]

Works like a charm.