2017-07-04 56 views
1

我需要以非常的方式更改类别值。GoJS撤销绑定到形状填充属性的类别属性的更改

代码:

diagram.startTransaction('changing state: ' + node.data.text); 
model.setDataProperty(node.data, 'category', 'stateInitial');    
diagram.commitTransaction('changing state: ' + node.data.text); 

节点模板:

$(go.Shape, 'RoundedRectangle', 
    { stroke: null , strokeWidth: 0 }, 
    new go.Binding("fill", "category", function(category){ 

     if(category == 'stateInitial'){ 
       return '#99AE3B'; 
      } 
      else if(category == 'stateFinal'){ 
       return '#E53935'; 
      } 
      return '#6699CC'; 
     }) 
    ), . . . 

该工程确定,该节点dinamcally改变其颜色。

但是,这样做后:

diagram.undoManager.undo(); 

节点交换机到模型中的一个类别(这是确定),但我看不出颜色的变回以前的颜色。 只有diagram.rebuildParts()方法有效,但我无法使用它。

有什么想法?

回答

0

类别(模板)是特殊的。改变节点类别时,请尝试使用Model.setCategoryForNodeData

如果您没有更改节点模板,请选择与“类别”不同的数据属性名称,因为它在GoJS模型中具有其他含义。