jsPlumb 如何删除重复的连接

Ser*_*e P 3 javascript jquery jsplumb

我试图避免在使用jsPlumb 时有重复的连接(2 个连接具有相同的源和目标)。有没有办法在不必修改 jsPlumb.js 本身的情况下做到这一点?

http://jsfiddle.net/uQdfq/
(从拖动task1task3 两次

我不想像 ( 1 )那样有添加特定端点的限制。

我的.tasks 在被调用时被定义为可能的目标/源 - 即整个 div 可以是源/目标,而不仅仅是某个端点:

  addTask($('#project1'), 'task' + 1);
Run Code Online (Sandbox Code Playgroud)

函数本身:

// Adds a task div to the specific project
function addTask(parentId, id) {
  var newState = $('<div>').attr('id', id).addClass('task')

  // A title for the task
  var title = $('<div>').addClass('title').text(id);
  newState.append(title);

  $(parentId).append(newState);

  // Makes the task div a possible target (i.e. connection can be dragged to)
  jsPlumb.makeTarget(newState, {
    anchor: 'Continuous'
  });

  // Makes the task div a possible source (i.e. connection can be dragged from)
  jsPlumb.makeSource(newState, {
    anchor: 'Continuous'
  });
}
Run Code Online (Sandbox Code Playgroud)

添加一些条件以阻止创建重复连接的可能性的最佳方法是什么。

cod*_*iot 5

jsPlumb.bind('connection',function(info){
 var con=info.connection;
 var arr=jsPlumb.select({source:con.sourceId,target:con.targetId});
 if(arr.length>1){
    jsPlumb.detach(con);
 }
});
Run Code Online (Sandbox Code Playgroud)

每当创建新连接时,检查是否已经存在具有相同源和目标的连接,如果是,则分离新连接。

  • 我收到这样的错误: jsPlumb: fire failed for event connection : TypeError: jsPlumb.detach is not a function。该怎么办? (2认同)