我写成
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 it = diagram.selection.iterator;
while (it.next()) {
var part = it.value;
if (part instanceof go.Node) {
part.addNodeData(node);
}
}
diagram.commitTransaction("color nodes");
}
我在这部分代码中遇到问题
while (it.next()) {
var part = it.value;
if (part instanceof go.Node) {
part.addNodeData(node);
}
}
我认为这行代码没有将节点附加到当前选定的节点
part.addNodeData(node);