Невозможно использовать переменную в методе связывания - PullRequest
0 голосов
/ 05 марта 2019

У меня есть код ниже

    jsPlumb.bind("ready", function() {          
                    jsPlumb.importDefaults({
                        Anchors  : ["RightMiddle", "LeftMiddle"],
                        EndpointStyles : [{ fillStyle:'#55636b' }, { fillStyle:'#55636b' }],
                        Endpoints : [ [ "Rectangle", {width:1, height:1} ], [ "Rectangle", { width:1, height:1 } ]],
                        ConnectionOverlays  : [
                            [ "Arrow", { location: -2 , width: 15, length: 15 } ]
                        ],
                        Connector:[ "Flowchart", { stub: 10, gap:10 } ],                                
                        PaintStyle  : {
                            lineWidth:2,
                            strokeStyle:"#55636b",
                            joinstyle:"round"
                        }
                    });

                //XSSOK
                    jsPlumb.connect({ source:'start', target:'task0' });
                    jsPlumb.connect({ source:'task0', target:'end' });
                });

в приведенном выше коде последние две строки, если я напрямую использую метод связывания, то он работает.

jsPlumb.connect({ source:'start', target:'task0' });
jsPlumb.connect({ source:'task0', target:'end' });

Но если я хранюто же значение в переменной и использовать переменную, то он перестал работать.

jsPlumb.bind("ready", function() {          
                        jsPlumb.importDefaults({
                            Anchors  : ["RightMiddle", "LeftMiddle"],
                            EndpointStyles : [{ fillStyle:'#55636b' }, { fillStyle:'#55636b' }],
                            Endpoints : [ [ "Rectangle", {width:1, height:1} ], [ "Rectangle", { width:1, height:1 } ]],
                            ConnectionOverlays  : [
                                [ "Arrow", { location: -2 , width: 15, length: 15 } ]
                            ],
                            Connector:[ "Flowchart", { stub: 10, gap:10 } ],                                
                            PaintStyle  : {
                                lineWidth:2,
                                strokeStyle:"#55636b",
                                joinstyle:"round"
                            }
                        });                 
                    sbConnections
                    });

Пожалуйста, помогите мне решить эту проблему, так как эти значения поступают из веб-службы.Я не могу жестко закодировать это здесь.

Ответы [ 2 ]

0 голосов
/ 07 марта 2019

Я решил эту проблему с помощью функции eval

jsPlumb.bind("ready", function() {          
                        jsPlumb.importDefaults({
                            Anchors  : ["RightMiddle", "LeftMiddle"],
                            EndpointStyles : [{ fillStyle:'#55636b' }, { fillStyle:'#55636b' }],
                            Endpoints : [ [ "Rectangle", {width:1, height:1} ], [ "Rectangle", { width:1, height:1 } ]],
                            ConnectionOverlays  : [
                                [ "Arrow", { location: -2 , width: 15, length: 15 } ]
                            ],
                            Connector:[ "Flowchart", { stub: 10, gap:10 } ],                                
                            PaintStyle  : {
                                lineWidth:2,
                                strokeStyle:"#55636b",
                                joinstyle:"round"
                            }
                        });                 
                    eval(sbConnections);
                    });
0 голосов
/ 07 марта 2019

Функции являются первоклассными объектами в JavaScript . Чтобы отделить соединение от связывания. Я бы сделал следующее:

var sbConnections = function () {
    jsPlumb.connect({ source:'start', target:'task0' });
    jsPlumb.connect({ source:'task0', target:'end' });
};

// Later on
jsPlumb.bind("ready", function() {
  jsPlumb.importDefaults({
    Anchors: ["RightMiddle", "LeftMiddle"],
    EndpointStyles: [{ fillStyle: '#55636b' }, { fillStyle: '#55636b' }],
    Endpoints : [ [ "Rectangle", {width:1, height:1} ], [ "Rectangle", { width:1, height:1 } ]],
    ConnectionOverlays: [[ "Arrow", { location: -2 , width: 15, length: 15 } ]],
    Connector:[ "Flowchart", { stub: 10, gap:10 } ],                                
    PaintStyle: {
        lineWidth: 2,
        strokeStyle: "#55636b",
        joinstyle: "round"
    }
  });

  // invoke the function
  sbConnections();
});
...