【发布时间】:2019-08-15 16:29:57
【问题描述】:
我将根据数据库中的数据绘制节点颜色变化的图表。我将通过数据库保存和加载 json 模型。问题是:如果db中的数据更新,如何触发更改节点颜色。
【问题讨论】:
标签: javascript gojs
我将根据数据库中的数据绘制节点颜色变化的图表。我将通过数据库保存和加载 json 模型。问题是:如果db中的数据更新,如何触发更改节点颜色。
【问题讨论】:
标签: javascript gojs
问题是:如果db中的数据更新,如何触发更改节点颜色。
我认为您的意思是:您如何更改模型数据以使图表反映更新?您必须使用Model.setDataProperty 或Model.set(别名)
https://gojs.net/latest/api/symbols/Model.html#setDataProperty
例子:
var node = myDiagram.findNodeForKey("Alpha");
// Model.commit executes the given function within a transaction
myDiagram.model.commit(function(m) { // this Model
// This is the safe way to change model data
// GoJS will be notified that the data has changed
// and can update the node in the Diagram
// and record the change in the UndoManager
m.set(node.data, "color", "red");
}, "change color");
// outputs "red" - the model has changed!
console.log(node.data.color);
这在GraphObject Manipulation tutorial 中进行了介绍,标题为使用数据绑定更改属性和更新模型。
【讨论】: