jsPlumb 如何删除重复连接
•浏览 1
jsPlumb how to remove duplicate connections
我试图避免在使用 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 = $('').attr('id', id).addClass('task')
// A title for the task
var title = $('').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);
}
});
函数本身:
addTask($('#project1'), 'task' + 1);
// Adds a task div to the specific project
function addTask(parentId, id) {
var newState = $('').attr('id', id).addClass('task')
// A title for the task
var title = $('').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);
}
});
添加一些条件以阻止创建重复连接的可能性的最佳方法是什么。
addTask($('#project1'), 'task' + 1);
// Adds a task div to the specific project
function addTask(parentId, id) {
var newState = $('').attr('id', id).addClass('task')
// A title for the task
var title = $('').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);
}
});
每当创建新连接时,请检查是否已经存在具有相同来源的连接