App data in generated JSON


I am working on a proof of concept application and everything is working very well. I have been reading the intro section and API, but I am unable to find the answer for the following situation. I need to assign a value to a graph element node or link, after the element has been created. I need the value to be included in the output generated by diagram.model.toJson().

The value is not available until after the node has been created and is interacted with via a context menu button which will initiate an ajax request to obtain the value.

I’ve noticed that all key/values that present in the original structure given to go.GraphLinksModel(data.nodes, data.links) are preserved. But I need to account for newly created nodes.

Is there an API function that may be called to create and populate user defined values in the nodes and links?


Just set the data properties that you want. If you want to be able to data bind to those properties with Bindings, or if you want support for undo/redo, be sure to call Model.setDataProperty rather than just assigning the property directly in JavaScript.

Presumably you have read the restrictions that Model.toJson and Model.fromJson have on the property names and their property values.