我正在研究jsPlumb问题。当我尝试以编程方式删除所有元素连接时,我得到Uncaught TypeError:无法读取未定义的属性“left”
我有几个“节点”(html元素),每个节点都有1个输入端点(一个接受的端点)和n个输出端点。每个节点后面还有一个javascript对象。我的软件中有“选定”状态。用户可以选择多个节点,并将对象推送到名为selected的数组。我有一个删除密钥的密钥监听器。按下该键时,它会循环选定的节点,删除它们并删除它们的端点。当没有连接时,这很有用,但是当有连接时我就错了。
输出端点附加到主节点的子HTML元素...
有很多代码在做很多事情,但我会尝试分享相关部分:
function Node(jsonFromServer){
/* … this is the constructor method… some code omitted*/
this.endpoints = [];
this.endpoints.push(jsPlumb.addEndpoint(this.el.attr("id"),targetEndpoint,{anchor:"TopCenter",uuid: this.el.attr("id") + "TopCenter"}));
this.addConnectionEndpoints();
}
Node.prototype.addConnectionEndPoints = function(){
//omitting code… loops through 'connections' that don't have 'has endpoint' marked….
this.endpoints.push(jsPlumb.addEndpoint(connection['el'].attr("id"),sourceEndpoint,{anchor:"RightMiddle",uuid:connection['el'].attr("id")+"RightMiddle"}));
connection.hasEndPoint = true;
}
这就是设置。这是我删除的方式
when key pressed
If key is delete /* all this stuff works */
loop through selected array (the array of selected Node elements:works)
node.el.hide(250).remove();
loop through node's endpoints array
//endpoint is the correct object... proved with console.log
//the following line is the error
jsPlumb.deleteEndpoint(endpoint);
ajax call to server to delete stuff on the backend
答案 0 :(得分:1)
修正了它!当我说node.el.hide(250).remove();我删除了删除过程中所需的html元素。我将删除部分移动到ajax请求的回调中,它就像一个魅力。