2015-11-04 87 views
0

基於示例http://gojs.net/latest/samples/flowchart.html我已經創建了看起來像下圖所示的自定義節點模板。GoJS自定義節點保存默認值

myDiagram.nodeTemplateMap.add("Action-node", 
    $(go.Node, "Spot", nodeStyle(), 
     $(go.Panel, "Auto", 
      $(go.Shape, "Rectangle", 
       { minSize: new go.Size(40, 40), fill: "#FF9191", stroke: null }), 
      $(go.Panel, "Vertical", 
       $(go.TextBlock, "Start", 
       { 
        font: "8pt Helvetica, Arial, sans-serif", 
        margin: 8, 
        stroke: lightText, 
        editable: true 
       }, 
       new go.Binding("text")), 
       $(go.TextBlock, "...", 
       { 
        font: "8pt Helvetica, Arial, sans-serif", 
        margin: 8, 
        stroke: lightText, 
        editable: true 
       }, 
       new go.Binding("text", "subtitle")) 
      ) 
     ), 
     // three named ports, one on each side except the top, all output only: 
     makePort("T", go.Spot.Top, false, true), 
     makePort("L", go.Spot.Left, true, false), 
     makePort("R", go.Spot.Right, true, false), 
     makePort("B", go.Spot.Bottom, true, false) 
    )); 

問題是,保存按鈕(保存()函數)調用

myDiagram.model.toJson(); 

只保存默認值JSON字符串。其他的東西,如位置和鏈接都保存正確。我的自定義模板是否存在問題,或者如何將更改保存在圖形中的節點值上?

回答

1

的基本想法是,如果(也許是由於用戶操作)的一些代碼的修改,一些GraphObject財產(如Node.locationTextBlock.text),你想會反映在更改後的值節點數據對象,則在該屬性上使用TwoWay 綁定

http://gojs.net/latest/intro/dataBinding.html處詳細瞭解數據綁定,特別是最後一節。

由於是最後一節表明,當你有一個TextBlock的編輯所以通常要進行綁定雙向的情況。那些你希望在模型中自動保存的屬性值?