Pankaj Bhandarkar
Pankaj Bhandarkar

Reputation: 498

GoJs - update the text and default properties of node by its key in graph

I want to dynamically change the text and default properties of nodes by their key in graph. I haven't found any option in the documentation for this.

Thanks.

Upvotes: 2

Views: 2304

Answers (1)

Walter Northwoods
Walter Northwoods

Reputation: 4146

I assume you are using a model. If so, you should make sure your node template uses data bindings for the properties that you want to modify.

Please read https://gojs.net/latest/intro/usingModels.html and https://gojs.net/latest/intro/dataBinding.html. Note in particular: https://gojs.net/latest/intro/dataBinding.html#ChangingDataValues.

This uses https://gojs.net/latest/api/symbols/Model.html#findNodeDataForKey and https://gojs.net/latest/api/symbols/Model.html#set :

var model = myDiagram.model;
var data = model.findNodeDataForKey(1234);
if (data) {
    model.startTransaction("modified property");
    model.set(data, "someBoundPropertyName", someNewValue);
    // ... maybe modify other properties and/or other data objects
    model.commitTransaction("modified property");
}

Upvotes: 4

Related Questions