I am adding a label to a link programmatically, which then displays on the diagram correctly.
When I persist the model, the link label does not appear in the JSON.
Please advise, thanks,
Ian.
function linkDoubleClick(e, obj) {
var nodeIndex = obj.data.from;
currentLink = obj;
var node = diagram.findNodeForKey(nodeIndex);
if (node.data.item == "Conditional") {
jQuery('#conditionalSelectModal').modal('show');
var index;
for (index = 0; index < node.data.Conditions.length; index++) {
jQuery('#ddlCondSelect').append(jQuery('<option>', {
value: node.data.Conditions[index].ConditionName,
text: node.data.Conditions[index].ConditionName
}));
}
}
}
jQuery('#conditionalSelectModal').on('hide.bs.modal', function (e) {
var textblock = new go.TextBlock();
textblock.text = jQuery('#ddlCondSelect').val();
textblock.margin = 5;
currentLink.add(textblock);
});
So every time you show the “#conditionalSelectModel” panel you expect to add a TextBlock to the Link?
If that is what you want, we need a longer discussion.
If instead you just want a single label on the link and you just want to modify the text, then I suggest you add the TextBlock to the Link template and add a TwoWay Binding of that TextBlock.text property to some property on your link data.
GoJS has a model-view architecture (actually M-V-VM). That typically means that the model is much simpler than the Diagram with its Nodes and Links consisting of many GraphObjects each with many properties. So the programmer is required to specify what needs to be saved in the model. For app-specific property values, that’s easy – just establish a TwoWay Binding. Structural changes to the graph are automatically handled by GoJS – creating/deleting node data and link data and changing relationships between them.
Also, whenever you make changes, you want to wrap all of the code in a transaction. That’s true whether you want to have multiple text labels or just a single one whose text is modified.