在GOJS图中linkvalidation返回false之后,图挂起

时间:2019-02-20 11:35:17

标签: gojs

我正在使用GoJS进行图表创建并使用版本1.8.33,并且我想在绘制节点之间的链接时应用验证。所以我用

this.diagram.toolManager.linkingTool.linkValidation = isDrawLink;
isDrawLink(fromnode, fromport, tonode, toport) {
return fromnode.data.name!==tonode.data.name
}

但是当此函数返回false时,我的图挂起,我无法在我的图上做任何事情。

1 个答案:

答案 0 :(得分:0)

我刚刚尝试了这段代码,其中包括您的链接验证功能:

  function init() {
    var $ = go.GraphObject.make;

    myDiagram =
      $(go.Diagram, "myDiagramDiv",
          {
            "linkingTool.linkValidation": function(fromnode, fromport, tonode, toport) {
              return fromnode.data.name !== tonode.data.name;
            }
          });

    myDiagram.nodeTemplate =
       $(go.Node, "Auto",
         $(go.Shape,
           { fill: "white", portId: "", fromLinkable: true, toLinkable: true, cursor: "pointer" },
           new go.Binding("fill", "color")),
         $(go.TextBlock,
           { margin: 8 },
           new go.Binding("text"))
       );

    myDiagram.model = new go.GraphLinksModel(
      [
        { key: 1, text: "Alpha", color: "lightblue", name: "A" },
        { key: 2, text: "Beta", color: "orange", name: "E" },
        { key: 3, text: "Gamma", color: "lightgreen", name: "A" },
        { key: 4, text: "Delta", color: "pink", name: "E" }
      ]);
  }

我无法重现任何问题。我尝试了1.8.33和2.0.3。