【问题标题】:jsplumb deleteEndpoint not working as expectedjsplumb deleteEndpoint 未按预期工作
【发布时间】:2013-09-18 05:10:54
【问题描述】:

我遇到了 jsPlumb 的 deleteEndpoint 函数的问题。

我想删除没有任何连接的端点。我希望它触发“连接”,但我认为那里可能存在一些问题。

但我将代码移至“dblclick”,但我看到了同样的问题。标记为删除的节点之一被删除,但系统中的每个端点都被冻结在原地 - 一旦被拖动,就与它的元素断开连接。我不确定是什么原因造成的:这是相关代码和一些屏幕截图......

jsPlumb.bind("dblclick", function(c) { 

            alert('starting...');

            var endpoints_to_delete = new Array();
            jsPlumb.selectEndpoints({source:c.sourceId}).each(function(endpoint) {
                if( endpoint.connections.length <= 0 )
                    endpoints_to_delete.push(endpoint);
            });
            jsPlumb.selectEndpoints({source:c.targetId}).each(function(endpoint) {
                if( endpoint.connections.length <= 0 )
                    endpoints_to_delete.push(endpoint);
            });

            alert(endpoints_to_delete.length); // 3

            $.each(endpoints_to_delete, function(endpoint) {
                jsPlumb.deleteEndpoint(endpoint);
            });

        }); 

这是我尝试删除端点之前的图表 - 所有端点仍然完好无损,它们所附加的可拖动元素。

在尝试删除端点后,每个端点都会与其元素断开连接...

【问题讨论】:

标签: javascript jquery jsplumb


【解决方案1】:

单独循环遍历每个元素并删除端点对我有用 - 我认为当我开始使用第一个元素的端点时,对第二个元素上的端点的引用会受到影响。氢。

    deleteEmptyEndpoints: function(element)
    {
        var endpoints_to_delete = [];
        jsPlumb.selectEndpoints({source:element}).each(function(endpoint) {
            console.log(endpoint);
            if( !!endpoint && endpoint.connections.length <= 0 )
            {
                console.log('marking ' + endpoint.getId() + ' for deletion');
                endpoints_to_delete.push(endpoint);
            }
        });

        $.each(endpoints_to_delete, function(index, endpoint) {
            console.log('deleting endpoint: ' + endpoint);
            jsPlumb.deleteEndpoint(endpoint);
            console.log('endpoint deleted');

        });
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-04
    • 2022-01-24
    • 2015-05-11
    • 2020-05-15
    • 2014-10-31
    • 2018-02-12
    • 2014-01-20
    • 2015-01-13
    相关资源
    最近更新 更多