0

UPDATED: Here is the fiddle: http://jsfiddle.net/janessaallen/c3b514wf/7/

Trying to figure out why the following will not get my jsplumb connections. I have a separate flowchart save javascript file with the following function for saving:

    function saveFlowchart() {
    var nodes = []

    $(".window").each(function (idx, elem) {
        var $elem = $(elem);
        var endpoints = jsPlumb.getEndpoints($elem.attr('id'));
        nodes.push({
            id: $elem.attr('id'),
            text: $elem.find($(".beneficiary")).text(),
            positionX: parseInt($elem.css("left"), 10),
            positionY: parseInt($elem.css("top"), 10)
        });
    });
    var connections = [];

    $.each(jsPlumb.getConnections(), function (idx, connection) {
            connections.push({
            connectionId: connection.id,
            sourceId: connection.sourceId,
            targetId: connection.targetId,
            anchors: $.map(connection.endpoints, function (endpoint) {

                return [[endpoint.anchor.x,
                endpoint.anchor.y,
                endpoint.anchor.orientation[0],
                endpoint.anchor.orientation[1],
                endpoint.anchor.offsets[0],
                endpoint.anchor.offsets[1]]];

            })
        });
    });

    var flowChart = {};
    flowChart.nodes = nodes;
    flowChart.connections = connections;
}

The endpoints work fine and get pushed to the array, but none of the connections are discovered by jsPlumb.getConnections.

jallen
  • 602
  • 12
  • 32
  • code looks fine. Create a fiddle demonstrating the issue. What does `jsPlumb.getAllConnections` return ? – coding_idiot Oct 02 '14 at 04:37
  • try changing `getConnections()` to `getAllConnections()` – coding_idiot Oct 02 '14 at 04:37
  • Hi, thank you. getAllConnections() does not work. Not sure how to even start with the fiddle for jsplumb...??? – jallen Oct 02 '14 at 11:50
  • This is basically what I am trying to accomplish: http://stackoverflow.com/questions/20620719/save-and-load-jsplumb-flowchart-including-exact-anchors-and-connections – jallen Oct 03 '14 at 13:01
  • Thanks. But I cannot get the connections. That is the only part that is missing. The connections won't be pushed to the array. – jallen Oct 03 '14 at 13:02
  • I updated my code to reflect more about what I am trying to do. – jallen Oct 03 '14 at 13:12
  • what version of `jsPlumb` are you using ? The link you mentioned contains a working `jsfiddle`. I am also working on a similar project - https://github.com/coding-idiot/jsPlumb-Persistence/blob/master/jsplumb-persistence-plugin.js – coding_idiot Oct 03 '14 at 13:58
  • Thanks. I just grabbed the latest version from the site last week. I'll check out your link and see if it may solve my connection issue. – jallen Oct 03 '14 at 14:48
  • Nope, can't get the connection populated with getAllConnections(). – jallen Oct 03 '14 at 15:05
  • It recognizes 'jsPlumb' but doesn't grab the connections. Just to clarify, if I draw them right on the page using the tool (by hand), shouldn't it recognize the connection in the DOM? – jallen Oct 03 '14 at 15:12
  • unless you can create a fiddle demonstrating the issue, I guess I'm out of possible reasons. – coding_idiot Oct 04 '14 at 05:03
  • I'm going to try to do that this weekend. It wouldn't let me add any libraries when last I tried. Stay tuned... – jallen Oct 04 '14 at 12:14
  • `http://bit.ly/1vCbsRD` take any of these. Clone & make your changes. – coding_idiot Oct 04 '14 at 12:29
  • I have the fiddle updated and posted in the original question. – jallen Oct 05 '14 at 13:06
  • @coding_idiot please can u check this https://github.com/nitinsurana/jsPlumb-Persistence/issues/2 – Eslam Magdy Jun 22 '20 at 15:54

1 Answers1

0

An instance of jsPlumb is created to create connections/makeSources/makeTargets, rather than using the global variable jsPlumb itself.

If an instance is used to create connections, then it has to be queried not the jsPlumb global variable.

I've updated the fiddle to save a reference to instance & used the instance to getAllConnections.

Updated fiddle http://jsfiddle.net/c3b514wf/8/

coding_idiot
  • 13,526
  • 10
  • 65
  • 116
  • Thanks! Getting closer, but it's still not recognizing the instance. – jallen Oct 06 '14 at 10:44
  • The issue is now the endpoints of the connections. So I will mark this as the answer. I will continue to troubleshoot the rest, but thank you so much for your help! – jallen Oct 06 '14 at 12:10