1

我正在处理一个 jsPlumb 问题。当我尝试以编程方式删除所有元素连接时,我得到 Uncaught TypeError: Cannot read property 'left' of undefined

我有几个“节点”(html 元素),每个节点都有 1 个输入端点(一个接受的端点)和 n 个输出端点。每个节点后面还有一个 javascript 对象。我的软件中有一个“选定”状态。用户可以选择多个节点,并将对象推送到一个名为 selected 的数组中。我有一个删除键的键监听器。当按下该键时,它会遍历选定的节点,删除它们并移除它们的端点。当没有连接时,这很好用,但是当有连接时,我会出错。

输出端点附加到主节点的子 HTML 元素...</p>

有很多代码可以做很多事情,但我会尝试分享相关部分:

 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
4

1 回答 1

1

修复!当我说 node.el.hide(250).remove(); 我删除了删除过程中所需的 html 元素。我将删除部分移到 ajax 请求的回调中,它就像一个魅力。

于 2012-11-21T18:04:52.187 回答