Change Node Text

Hi team,

I need to change the text of the node through a java script function.

how can I do this ?

Within a transaction, call Model.setDataProperty on the desired Node’s data, the name of the bound text property, and the new text string.

This is assuming that your Node template has a Binding of TextBlock.text to your data’s text property. You will find many examples of this in the samples and in the Introduction, for example: http://www.gojs.net/latest/intro/dataBinding.html.

Hi Walter,

I am trying it in the following way,

function changeNodeText(){
var fieldText = document.getElementById(“stepname”).value;
var selectShape = elem.findObject(“SHAPE”);
var selectText = elem.findObject(“TEXT”);
myDiagram.model.setDataProperty(selectShape.part,selectText.text,fieldText);
}

but not able to change the text.

Please suggest.

Did you see any errors or warnings in the console? Did you see how Model.setDataProperty is being called in the Introduction or in the samples that use it? It is working on model data, not on Nodes or Links. That’s why I was assuming you had a Binding of TextBlock.text to your model node data text property. That way also you won’t need to specify "name"s to your GraphObjects in your template(s).

And remember that all of your changes need to be wrapped in a single transaction. I cannot tell if your changeNodeText function is being called within a transaction.

how can I get hold of the selected node in the javascript function.

Use Diagram.selection, http://gojs.net/latest/api/symbols/Diagram.html#selection.
Caution: there might be more than one selected Part, and none of them might be Nodes.