I'm writing a test application using go.js. This application lets the user dynamically add nodes, move existing nodes and connect them to each other.
The initial state of the diagram is described by this model:
var nodeDataArray = [
{ key: "a", operation: "concat" },
{ key: "b" },
{ key: "c" },
{ key: "d", loc: new go.Point(30, 50) }
];
var linkDataArray = [
{from: "a", to: "b", toPort: "A"}
];
Now I have this problem. When I output my updated model with myDiagram.model.toJson()
I always get the original model regardless any change the user did in the meantime. Is there a better way to output the current state of the diagram?
Thanks
No, calling Model.toJson is the best way to get the current state of the model. The question is how well the model data reflects what you see in the diagram.
If the user had added or removed any nodes or links, you would see that in the toJson() output.
If there were a TwoWay Binding on Node.location and if the user had moved some of the nodes, the new positions would be reflected in the model data.
If the user had somehow modified the "operation" of a node, via some code in your app, that should also be reflected in the model data, assuming your code modified the data and not the GraphObject(s) directly without making use of a TwoWay Binding.