我试图在使用 jsPlumb 时避免重复连接(2 个连接具有相同的源和目标) .有没有一种方法可以做到这一点而不必修改 jsPlumb.js 本身?
http://jsfiddle.net/uQdfq/
(从task1
拖到task3
两次)
我不想像在 ( 1 ) 中那样受到添加特定端点的限制。
我的 .task
在被调用时被定义为可能的目标/源 - 即整个 div 可以是源/目标,而不仅仅是一些端点:
addTask($('#project1'), 'task' + 1);
函数本身:
// 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'
});
}
添加一些条件以阻止创建重复连接的可能性的最佳方法是什么。
最佳答案
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);
}
});
每当创建一个新连接时,检查是否已经存在具有相同源和目标的连接,如果是,则分离新连接。
关于javascript - jsPlumb如何去除重复的连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24154919/