如何从GoJS的DataInspector扩展中获取文本值?

时间:2019-11-07 01:53:54

标签: javascript gojs

我正在使用Data Inspector扩展名,如here所示:

  • 我想简单地在其中一个字段中输入数字(即 maxLinks)设置所选链接允许的最大链接数 节点。如何检索在其中一个字段中输入的输入?

  • 此外,是否可以对可编辑文本字段执行相同操作(检索 文字输入)?

非常感谢。

1 个答案:

答案 0 :(得分:0)

在您所引用的示例以及典型的用法中,例如在示例组织结构图编辑器https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webdriver.WebDriver.find_elements_by_css_selector中,DataInspector都会在模型中显示所选节点的数据对象的属性。其中一些属性是可编辑的。当用户修改值并失去焦点时,检查器代码将提交事务以修改该数据对象的属性值。

因为在节点(或链接)模板中存在一些 GraphObject 属性的 Binding 调用 Model.set 的data属性将更新相应的GraphObject属性,这将导致图更新。

在您的情况下,您需要从节点数据对象上的“ maxLinks”属性绑定 GraphObject.fromMaxLinks 。这显示在下面的“节点”模板中。

请注意 TextBlock.text 绑定的工作方式,以便用户可以就地编辑文本或在Inspector中对其进行编辑。

完整示例:

<!DOCTYPE html>
<html>
<head>
<title>GoJS Sample Using DataInspector</title>
<!-- Copyright 1998-2019 by Northwoods Software Corporation. -->
<meta charset="UTF-8">
<script src="https://unpkg.com/gojs"></script>
<link rel="stylesheet" href="../extensions/DataInspector.css" />
<script src="../extensions/DataInspector.js"></script>
<script id="code">
  function init() {
    var $ = go.GraphObject.make;

    myDiagram =
      $(go.Diagram, "myDiagramDiv",
          { "undoManager.isEnabled": true });

    myDiagram.nodeTemplate =
      $(go.Node, "Auto",
        $(go.Shape,
          { fill: "white", portId: "", fromLinkable: true, toLinkable: true, cursor: "pointer" },
          // THIS IS THE CRUCIAL BINDING, from data.maxLinks to GraphObject.fromMaxLinks
          new go.Binding("fromMaxLinks", "maxLinks"),
          new go.Binding("fill", "color")),
        $(go.TextBlock,
          { margin: 8, editable: true },
          new go.Binding("text").makeTwoWay())
      );

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

    var inspector = new Inspector("myInspectorDiv", myDiagram,
      {
        properties:
        {
          key: { readOnly: true, show: Inspector.showIfPresent },
          maxLinks: { type: "number", defaultValue: Infinity, show: Inspector.showIfNode }
        }
      });
  }
</script>
</head>
<body onload="init()">
  <div id="myDiagramDiv" style="border: solid 1px black; width:100%; height:600px"></div>
  <div id="myInspectorDiv" class="inspector"></div>
</body>
</html>