gojs访问绑定内的目标对象

时间:2018-01-23 23:18:10

标签: javascript gojs

尝试在goJS图表中创建一些用户权限。有没有办法在绑定函数中访问目标对象。我有图表我的节点和链接有“feAttr”(可以是真或假),我想在绑定函数中访问该属性,但没有示例如何做到这一点。

这是我的节点模板的示例,我想在其中访问其属性:

myDiagram.nodeTemplate =
          $(go.Node, "Auto",
            new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify),
            // define the node's outer shape, which will surround the TextBlock
            $(go.Shape, "RoundedRectangle",
              {
                parameter1: 20,  // the corner has a large radius
                fill: $(go.Brush, "Linear", { 0: "rgb(254, 201, 0)", 1: "rgb(254, 162, 0)" }),
                stroke: null,
                portId: "",  // this Shape is the Node's port, not the whole Node
                fromLinkable: true, fromLinkableDuplicates: true,
                toLinkable: true, toLinkableDuplicates: true,
                cursor: "pointer"
              }),
            $(go.TextBlock,
              {
                font: "bold 11pt helvetica, bold arial, sans-serif",
                editable: true  // editing the text automatically updates the model data
                //textEditor: window.TextEditorRadioButtons, // defined in textEditorRadioButtons.js
                // this specific TextBlock has its own choices:
              },
          new go.Binding("editable", "text", function(t) { 
            console.log("inside node binding editable!");

            console.log("NEED TO ACCESS TARGET OBJECT, BUT HOW ???");

            return (targetObject.data.feAttr && t === "?"); 

          }),
            new go.Binding("text").makeTwoWay())
        );

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

您可以在绑定转换函数中指定第二个参数。请阅读"高级转化" https://gojs.net/latest/api/symbols/Binding.html的一部分。