【发布时间】:2019-11-07 01:53:54
【问题描述】:
我使用的是Data Inspector扩展,如图here:
我只想在其中一个字段中输入一个数字(即 maxLinks) 设置所选链接的最大允许链接数 节点。如何检索在其中一个字段中输入的输入?
此外,是否可以对可编辑的文本字段进行相同操作(检索 文本输入)?
非常感谢。
【问题讨论】:
标签: javascript gojs
我使用的是Data Inspector扩展,如图here:
我只想在其中一个字段中输入一个数字(即 maxLinks) 设置所选链接的最大允许链接数 节点。如何检索在其中一个字段中输入的输入?
此外,是否可以对可编辑的文本字段进行相同操作(检索 文本输入)?
非常感谢。
【问题讨论】:
标签: javascript gojs
在您引用的示例中,以及在示例组织结构图编辑器https://gojs.net/latest/samples/orgChartEditor.html 等典型用法中,DataInspector 显示模型中选定节点的数据对象的属性。其中一些属性是可编辑的。当用户修改值并且焦点丢失时,检查器代码提交一个事务来修改该数据对象的属性值。
由于Node(或Link)模板中有一些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>
【讨论】: