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

How do you get the text value from the DataInspector extension in GoJS?

我正在使用数据检查器扩展,如图所示here

非常感谢。

在您引用的示例中,以及在组织结构图编辑器示例中的典型用法中,https://gojs.net/latest/samples/orgChartEditor.html,DataInspector 显示模型中所选节点的数据对象的属性。其中一些属性是可编辑的。当用户修改值并且焦点丢失时,检查员代码提交事务以修改该数据对象的 属性 值。

因为Node[=29=中有一些GraphObject属性的Binding ](或Link)模板,通过调用Model.set修改数据属性会更新相应的GraphObject 属性,这将导致图表更新。

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

请注意 TextBlock.text 绑定的工作原理,以便用户可以就地编辑文本或在检查器中进行编辑。

完整样本:

<!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>