I have the following code here:
myDiagram.addDiagramListener("ExternalObjectsDropped", function (e) {
document.getElementById("myDiagram").focus();
myDiagram.toolManager.draggingTool.reset(); // remove any guidelines
var deviceNode = e.diagram.selection.first();
deviceNode.data.key = "myId";
if (myDiagram.findNodeForKey("myId")) {
console.info("true");
} else {
console.info("false");
}
Why is it I always get false?
I have tried getNodeForKey and getPartForKey, both yields the same result.
From the documentation for Model, http://gojs.net/latest/api/symbols/Model.html :
[quote]This model cannot detect the modification of the #nodeDataArray array or the modification of any node data object. If you want to add or remove node data from the #nodeDataArray, call the #addNodeData or #removeNodeData methods.
If you want to modify a node data object, it depends on whether the property you want to change is a structural property that the model needs to know about, or whether it is a property that is only used for data binding or other application-specific purposes.
For the former case, call the appropriate method, such as#setKeyForNodeData, #setCategoryForNodeData,GraphLinksModel#setToKeyForLinkData, or GraphLinksModel#setGroupKeyForNodeData. These methods have names that start with “set”, “add”, “insert”, or “remove”.
For the latter case, when setting an application-specific property, typically for data binding, and to support undo/redo, call #setDataProperty.[/quote]