如何以编程方式更改 mxCell 值?
How to change an mxCell value programmatically?
我在 json 中有一个带有 "logical" 表示的图形(我用于另一个程序)并且图形表示在 MxGraph 中,在 Angular 组件中呈现.
我使用 XML 作为单元格的值,正如 Documentation 中所建议的那样。
虽然对我来说拦截 mxgraph 中的变化并更新 json 非常容易,但我无法在图中传播 json 中的变化。
一个愚蠢的例子是如果我改变了 "label" 的值。我可以这样做:
editor.graph.model.cells[2].value.setAttribute('label', "Test");
但此更改仅在发生另一次更新时可见(例如,移动图中的单元格)。
我试图触发一个 mxEvent.CHANGE 事件,但我无法正确设置编辑和更改,以便它们传播到图表。我也尝试创建一个新的 mxGeometryChange,但我又失败了...
提前感谢任何提示...
我找到了一个解决方案,即使我不能使用它...这是我添加的功能:
// To use it call:
// graph.updateCell(cell, "newlabel");
graph.updateCell = function(cell, label)
{
if (cell !== null) {
cell.value.setAttribute('label', label);
this.model.beginUpdate();
try
{
//this.cellUpdated(cell);
this.model.setValue(cell, cell.value);
this.fireEvent(new mx.mxEventObject(mx.mxEvent.LABEL_CHANGED,
'cell', cell, 'ignoreChildren', false));
}
finally
{
this.model.endUpdate();
}
return cell;
} else return null;
};
我的问题是我不能使用这个功能,但此时问题不同了。原因是我想从另一个不是 运行 mxgraph 的组件使用这个函数,这就是我现在的挣扎......这变成了一个关于 Angular ngModel 前向和后向引用的问题.. .我可能会在另一个 post...
上问
适合我的解决方案。
我们应该使用mxGraphModel.setValue
。
然后,变化就可见了。
mxCell.setValue
无法显示。
谢谢!
我在 json 中有一个带有 "logical" 表示的图形(我用于另一个程序)并且图形表示在 MxGraph 中,在 Angular 组件中呈现.
我使用 XML 作为单元格的值,正如 Documentation 中所建议的那样。
虽然对我来说拦截 mxgraph 中的变化并更新 json 非常容易,但我无法在图中传播 json 中的变化。
一个愚蠢的例子是如果我改变了 "label" 的值。我可以这样做:
editor.graph.model.cells[2].value.setAttribute('label', "Test");
但此更改仅在发生另一次更新时可见(例如,移动图中的单元格)。
我试图触发一个 mxEvent.CHANGE 事件,但我无法正确设置编辑和更改,以便它们传播到图表。我也尝试创建一个新的 mxGeometryChange,但我又失败了...
提前感谢任何提示...
我找到了一个解决方案,即使我不能使用它...这是我添加的功能:
// To use it call:
// graph.updateCell(cell, "newlabel");
graph.updateCell = function(cell, label)
{
if (cell !== null) {
cell.value.setAttribute('label', label);
this.model.beginUpdate();
try
{
//this.cellUpdated(cell);
this.model.setValue(cell, cell.value);
this.fireEvent(new mx.mxEventObject(mx.mxEvent.LABEL_CHANGED,
'cell', cell, 'ignoreChildren', false));
}
finally
{
this.model.endUpdate();
}
return cell;
} else return null;
};
我的问题是我不能使用这个功能,但此时问题不同了。原因是我想从另一个不是 运行 mxgraph 的组件使用这个函数,这就是我现在的挣扎......这变成了一个关于 Angular ngModel 前向和后向引用的问题.. .我可能会在另一个 post...
上问适合我的解决方案。
我们应该使用mxGraphModel.setValue
。
然后,变化就可见了。
mxCell.setValue
无法显示。
谢谢!