【问题标题】:jsPlumb - detach connection with sourceId == targetIdjsPlumb - 使用 sourceId == targetId 分离连接
【发布时间】:2015-03-01 00:45:27
【问题描述】:

我是 jsPlumb 的新手,我在连接具有相同源和目标的连接时遇到问题。我必须禁止这些类型的连接,我认为最好的方法是:当我完成创建连接时,如果它具有相同的 sourceId 和 targetId,则删除该连接。 我正在这样做:

jsPlumb.bind('connection', function(info) { 
    console.log('connection bind - From: ' + info.sourceId + ' To: ' + info.targetId);

    if (info.sourceId == info.targetId) {
        console.log('sourceId == targetId');
        jsPlumb.detach(info);
    }
});

但是发生的事情是这样的

连接已删除,但看起来源端点仍然存在,但是,如果我拖动项目,点会停留在同一个位置,就好像它不再引用该项目一样,这没关系,因为连接是已删除,但不行,因为那个点不应该在那里。

对此有什么意见吗? 谢谢。

【问题讨论】:

    标签: javascript jquery jsplumb


    【解决方案1】:

    我解决了这个问题:

    jsPlumb.bind("connectionDragStop", function (connection) {
        //console.log("connectionDragStop");
        if (connection.sourceId == connection.targetId) {
            //console.log('sourceId == targetId');
            alert("Connections with the same source and target aren't allowed. The connection will be deleted.");
            jsPlumb.detach(connection);
        }
    });
    

    现在运行良好。

    【讨论】:

      猜你喜欢
      • 2022-01-12
      • 2016-11-02
      • 1970-01-01
      • 1970-01-01
      • 2015-07-16
      • 1970-01-01
      • 2013-09-12
      • 1970-01-01
      • 2013-06-16
      相关资源
      最近更新 更多