1
我正在處理jsPlumb問題。當我嘗試以編程方式刪除所有元素連接時,我得到未捕獲的TypeError:無法讀取未定義的屬性'左'jsPlumb刪除元素的連接
我有幾個「節點」(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