javascript - How to add node to parent node (currently selected node) in gojs? -
i have written
function attachlink() { var url = "https://www.google.co.in"; var diagram = mycontextmenu.diagram; var node = new go.node(go.panel.auto); var shape = new go.shape(); shape.figure = "roundedrectangle"; shape.fill = "lightblue"; node.add(shape); var textblock = new go.textblock(); textblock.text = "hello!"; textblock.margin = 5; textblock.cursor = "pointer"; textblock.click = function (e, obj) { window.open(url) }; node.add(textblock); //diagram.add(node); //var diagram = mycontextmenu.diagram; var = diagram.selection.iterator; while (it.next()) { var part = it.value; if (part instanceof go.node) { part.addnodedata(node); } } diagram.committransaction("color nodes"); }
i having trouble in part of code
while (it.next()) { var part = it.value; if (part instanceof go.node) { part.addnodedata(node); } }
i think line of code not appending node selected node
part.addnodedata(node);
addnodedata
function of model
in gojs. adding graphobject
(in case go.node
programmatically built) parent node's visual tree involve calling add
on parent node.
parentnode.add(childnode)
this same function used when adding go.shape
, go.textblock
node programmatically built.
one thing worry approach though you're adding reference same go.node
each graphobject
in mydiagram.selection
. want build go.node
want add each element selected in while loop such constructor invoked each time , you're adding distinct go.node
s each selected element rather same one.
Comments
Post a Comment