Search code examples
javascriptjquerystate-machinejsplumb

Getconnection() not working for state machine


I am using jsPlumb statemachine. I would like to save and load my chart later. I googled and found that I would have to do it using json Object. I tried few examples stackoverflow. I am able to get the positions of each of the box but I cannot get connections. All the examples I saw uses jsPlumb.getConnections() but for me it isn't working. I have added these connections and boxes dynamically.


Solution

  • If you are modifying example code you need to make 'instance' variable global and then call getConnections() method on it.

    instance = jsPlumb.getInstance({
            Endpoint: ["Dot", {radius: 1}],
            HoverPaintStyle: {strokeStyle: "#1e8151", lineWidth: 1},
            ConnectionOverlays: [
                ["Arrow", {
                        location: 1,
                        id: "arrow",
                        length: 10,
                        width: 15,
                        foldback: 1
                    }],
                ["Label", {label: "FOO", id: "label", cssClass: "aLabel"}]
            ],
            Container: "statemachine"
        });
    
     //...
    
    instance.getConnections()