2012-11-21 5 views
1

jsPlumb 문제를 해결하고 있습니다. 프로그래밍 방식으로 모든 요소 연결을 제거하려고하면 Uncaught TypeError가 발생합니다. 정의되지 않은 'left'속성을 읽을 수 없습니다.jsPlumb 요소 연결 삭제

각 입력 끝 점이 하나씩있는 여러 개의 "노드"(html 요소)가 있습니다 (끝 점은 accepts) 및 n 개의 출력 엔드 포인트를 포함합니다. 각 노드에는 그 뒤에 자바 스크립트 객체가 있습니다. 내 소프트웨어에는 "선택된"상태가 있습니다. 사용자는 여러 개의 노드를 선택할 수 있으며 객체는 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 

답변

1

고쳐졌습니다. node.el.hide (250) .remove();라고 말했을 때. 삭제 프로세스에서 필요한 html 요소를 제거했습니다. remove 부분을 Ajax 요청의 콜백으로 옮겼고, 매력처럼 작동합니다.