Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript GOJS,如何将数据绑定到组属性?_Javascript_Gojs - Fatal编程技术网

Javascript GOJS,如何将数据绑定到组属性?

Javascript GOJS,如何将数据绑定到组属性?,javascript,gojs,Javascript,Gojs,我已经启动并运行了一个GOJS应用程序,我正在尝试将数据中的一个参数绑定到group属性 如果我在数据中手动设置组属性,那么它的工作方式与我预期的完全相同,节点显示为组的一部分,但是如果使用绑定设置组,则似乎不会建立组连接 我错过了什么 显示在数据中设置的组的示例 var nodes = [] var nodeObj ={ key:"groupObject", text:"group", isGroup:true } nodes.push(nodeObj)

我已经启动并运行了一个GOJS应用程序,我正在尝试将数据中的一个参数绑定到group属性

如果我在数据中手动设置组属性,那么它的工作方式与我预期的完全相同,节点显示为组的一部分,但是如果使用绑定设置组,则似乎不会建立组连接

我错过了什么

显示在数据中设置的组的示例

var nodes = []
var nodeObj ={
    key:"groupObject",
    text:"group",
    isGroup:true
  }
  nodes.push(nodeObj)

  nodeObj = {
    key:"node1",
    text:"node1",
    group:"groupObject"
  }
  nodes.push(nodeObj)

  nodeObj = {
    key:"node2",
    text:"node2",
    group:"groupObject"
  }
  nodes.push(nodeObj)
}

const initDiagram = () => {
    const $ = go.GraphObject.make;
    const diagram =
      $(go.Diagram,
        {
          'undoManager.isEnabled': true,
          'clickCreatingTool.archetypeNodeData': { text: 'new node', color: 'lightblue' },
          model: $(go.GraphLinksModel,
            {
              linkKeyProperty: 'key' 
            })
      });

    diagram.nodeTemplate = 
        $(go.Node, 'Auto',
            $(go.Shape, 'RoundedRectangle',
            { name: 'SHAPE', fill: 'white', strokeWidth: 0 },
            new go.Binding('fill', 'color')),
            $(go.TextBlock,
            { margin: 8, editable: true, stroke:"black" },
            new go.Binding('text').makeTwoWay()
            )
        );

    diagram.groupTemplate = 
      $(go.Group, "Vertical", $(go.GridLayout,{wrappingColumn:1}),
        $(go.TextBlock,         // group title
          { alignment: go.Spot.Center, font: "Bold 15pt Sans-Serif" },
          new go.Binding("text")),  
        $(go.Panel, "Auto",
          $(go.Shape, "RoundedRectangle",  // surrounds the Placeholder
            {fill: "lightblue" }),
          $(go.Placeholder,
            { padding: 5}),
        )
    );
    return diagram;
  }
这很有效^^^

现在,如果我将数据中的group参数设置为“groupName”而不是group,然后在init函数中将group绑定到groupName,则节点不再作为组的一部分出现

var nodes = []
var nodeObj ={
    key:"groupObject",
    text:"group",
    isGroup:true
  }
  nodes.push(nodeObj)

  nodeObj = {
    key:"node1",
    text:"node1",
    groupName:"groupObject"      //this line has changed
  }
  nodes.push(nodeObj)

  nodeObj = {
    key:"node2",
    text:"node2",
    groupName:"groupObject"      //This line has changed
  }
  nodes.push(nodeObj)
}

const initDiagram = () => {
    const $ = go.GraphObject.make;
    const diagram =
      $(go.Diagram,
        {
          'undoManager.isEnabled': true,
          'clickCreatingTool.archetypeNodeData': { text: 'new node', color: 'lightblue' },
          model: $(go.GraphLinksModel,
            {
              linkKeyProperty: 'key'
            })
      });

    diagram.nodeTemplate = 
        $(go.Node, 'Auto',
            new go.Binding('group','groupName'),      //this line has changed
            $(go.Shape, 'RoundedRectangle',
            { name: 'SHAPE', fill: 'white', strokeWidth: 0 },
            new go.Binding('fill', 'color')),
            $(go.TextBlock,
            { margin: 8, editable: true, stroke:"black" },
            new go.Binding('text').makeTwoWay()
            )
        );

    diagram.groupTemplate = 
      $(go.Group, "Vertical", $(go.GridLayout,{wrappingColumn:1}),
        $(go.TextBlock,         // group title
          { alignment: go.Spot.Center, font: "Bold 15pt Sans-Serif" },
          new go.Binding("text")),  
        $(go.Panel, "Auto",
          $(go.Shape, "RoundedRectangle",
            {fill: "lightblue" }),
          $(go.Placeholder,
            { padding: 5}),
        )
    );
    return diagram;
  }

绑定用于使一个零件的GraphObject的属性与该零件模型数据的属性保持最新。绑定不用于维护零件之间的关系。只有模型才知道如何解释和维护关系

如果要使用数据属性“groupName”而不是“group”来引用节点的包含组,请将GraphlinkModel.nodeGroupKeyProperty设置为“groupName”。最好在设置Model.nodeDataArray之前


另外,请阅读。

谢谢,我似乎误解了绑定的概念。