【问题标题】:JsPlumb get all connection from start elementJsPlumb 从开始元素获取所有连接
【发布时间】:2019-07-30 05:14:53
【问题描述】:

如何从第一个元素获取所有连接。

在 JsPlumb.getAllConnection() 的帮助下,它只返回第二个连接。 我正在尝试获取所有连接和所有要从中获取数据的元素。

我的代码:

$.each(jsPlumb.getAllConnections(), function (idx, connection) {
            idx++;
            console.log("idx" + idx);
            for (var i = 0; i <= idx; i++) {
                var replyOnes = connection.target.childNodes;
                var varStoreHere = [];
                for (var x = 1; x < replyOnes.length; x++) {
                    varStoreHere.push({
                        question: replyOnes[x].innerText,
                        answer: connection.target.id
                    });
                };
            };

            connections.push({
                id: connection.source.offsetParent.offsetParent.id,
                pageTargetId: connection.targetId,
                says : [connection.target.firstChild.innerText],
                reply : varStoreHere
            });

        });

返回值:两个元素,但只输出没有两个的连接元素,第一个元素丢失

{
    "connections": [
        {
            "id": "pro2",
            "pageTargetId": "state1",
            "says": [
                null
            ],
            "reply": [
                {
                    "question": "",
                    "answer": "state1"
                }
            ]
        }
    ],
    "numberOfElements": 0
}

【问题讨论】:

    标签: javascript jquery html css jsplumb


    【解决方案1】:

    idx++; 移到底部,当它位于函数的开头时,您将从第二个 id 开始 for 循环

    $.each(jsPlumb.getAllConnections(), function (idx, connection) {
        for (var i = 0; i <= idx; i++) {
            var replyOnes = connection.target.childNodes;
            var varStoreHere = [];
            for (var x = 1; x < replyOnes.length; x++) {
                varStoreHere.push({
                    question: replyOnes[x].innerText,
                    answer: connection.target.id
                });
            };
        };
    
        connections.push({
            id: connection.source.offsetParent.offsetParent.id,
            pageTargetId: connection.targetId,
            says : [connection.target.firstChild.innerText],
            reply : varStoreHere
        });
        idx++;
        console.log("idx" + idx);
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多