1
我試圖設置gojs圖模型的nodeKeyProperty
。以下代碼是我正在嘗試做的 -GoJS - 未捕獲錯誤:[object Object]上的Model.makeNodeDataKeyUnique失敗
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gojs/1.6.7/go-debug.js"></script>
</head>
<body>
<div id="myDiagramDiv" style="width:400px; height:150px; background-color: #DAE4E4;"></div>
<script type="text/javascript">
var $ = go.GraphObject.make;
var diagram = $(go.Diagram, "myDiagramDiv");
diagram.nodeTemplate = $(go.Node, "Auto",
$(go.Shape, "RoundedRectangle", new go.Binding("fill", "fill").makeTwoWay()),
$(go.TextBlock, new go.Binding("text", "id"))
);
diagram.model = new go.GraphLinksModel();
diagram.model.nodeKeyProperty = function(nodeData, id) {
// id && (nodeData.id = id);// enabling it will fix the issue.
return nodeData.id;
};
diagram.model.addNodeData({
fill:"green"
})
</script>
</body>
</html>
但我無法成功運行此代碼。我收到以下錯誤 -
Uncaught Error: Model.makeNodeDataKeyUnique failed on [object Object]. Data not added to Model.
at Object.k (go-debug.js:31)
at X.L.addNodeData.L.vl (go-debug.js:356)
at index-copy.html:26
我試着調試gojs代碼並以某種方式想通了,加入到id && (nodeData.id = id)
實施nodeKeyProperty
修復問題。但是,從docs其不清楚,如果它是必需的。我做錯了什麼?
在此先感謝。
謝謝,是的,只是設置「ID」會起作用,但我正在試驗它,因爲後來的ID可以進入深處的對象。 –