Ales
Ales

Reputation: 537

GoJS Custom node saves default values

Based on example http://gojs.net/latest/samples/flowchart.html I've created custom node templates that look like the one bellow.

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)
    ));

Problem is that save button (save() function) that calls

myDiagram.model.toJson(); 

saves only default values to json string. Other things like location and and link are saved correctly. Is there a problem with my custom template or how can I save changes on node values in graph?

Upvotes: 0

Views: 704

Answers (1)

Walter Northwoods
Walter Northwoods

Reputation: 4146

The basic idea is that if some code (perhaps because of user action) changes some GraphObject property (such as Node.location or TextBlock.text) and you want the changed value to be reflected in the node data object, you use a TwoWay Binding on that property.

Read more about data binding at http://gojs.net/latest/intro/dataBinding.html, especially the last section.

As that last section suggests, when you have a TextBlock that is editable it is normally the case that you want to make the Binding TwoWay. Are those the property values that you were hoping to be saved automatically in the Model?

Upvotes: 1

Related Questions