移动节点后获取位置

时间:2019-08-12 09:19:30

标签: javascript gojs

移动节点以保存到数据库新位置后如何获取当前位置。

{{1}}

但是该部分始终为空,为什么?

2 个答案:

答案 0 :(得分:0)

e.subject是一个集合,是所有移动部件的选择。可能移动了多个部分。

如果您有合理的把握只移动了一个声部,则可以编写:

myDiagram.addDigramListener("SelectionMoved",
  function(e) {
    let part = e.subject.first();
    console.log(part.toString())
  }
)

但是,如果您只想将位置保存到数据库中,为什么不对Location进行双向数据绑定呢? flowchart example演示了这一点:

// The Node.location comes from the "loc" property of the node data,
// converted by the Point.parse static method.
// If the Node.location is changed, it updates the "loc" property of the node data,
// converting back using the Point.stringify static method.
new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify),

答案 1 :(得分:0)

我能够使用以下代码获取新的位置和密钥


myDiagram.addDiagramListener("SelectionMoved", function(event) {

  // https://gojs.net/latest/api/symbols/Part.html#location
  // * PART
  var selectedNode = event.diagram.selection.first();

  console.log("selectedNode",selectedNode);
  console.log("selectedNodeKey",selectedNode.key);
  console.log("selectedNode", selectedNode.location.toString());
  console.log("selectedNode", selectedNode.location.x);
  console.log("selectedNode", selectedNode.location.y);
  console.log("locationObject", selectedNode.locationObject);

  //Save new location
  // key: selectedNode.key
  // location-x: selectedNode.location.x
  // location-y: selectedNode.location.y

});