当前位置:网站首页>jsPlumb. Deleteeveryconnection is not a function & jsplumb clear canvas jsplumb delete all nodes and all connections

jsPlumb. Deleteeveryconnection is not a function & jsplumb clear canvas jsplumb delete all nodes and all connections

2022-06-30 14:24:00 mizuhokaga

0. problem

Using jsPlumb.deleteEveryConnection Delete all connection errors
jsPlumb.deleteEveryConnection is not a function!

1. solve

jsPlumb.js The version is Community Edition Community Edition 1.7.6.
my jsPlumb yes cdn Introduced , Go directly to the web page to view js Source file .
Find out deleteEveryConnection Method really can't find , Then I turned it over , Found... In the file detachEveryConnection()
Use

jsPlumb.detachEveryConnection();

after The error report disappears and the problem is solved

2.jsPlumb Delete all nodes and wires on the canvas

There are... On the canvas node 、 Lines and endpoints . Where the line and the endpoint are jsplumb Maintenance of , Nodes need to be maintained by ourselves .

jsPlumb There are only

  • Delete the endpoints of all nodes detachEveryConnection
  • Delete all connections deleteEveryEndpoint
    These two methods , For node deletion, I only found remove(id) Method

therefore JsPlumb The idea of clearing the canvas is as follows :
Find your own way to clear the nodes ( I use remove Method ), then jsplumb The generated endpoints and wires are generated by jsplumb The two above api Clean up .

tableID=new Array();
function clear(){
    
    clearAllNode();
    jsPlumb.detachEveryConnection();
    jsPlumb.deleteEveryEndpoint ()

}
function clearAllNode(){
    
    if(tableID.length!==0){
    
        tableID.forEach(id=>{
    
            jsPlumb.remove(id)
        })
    }
}

tableID Is the storage node id Array of , You need to store the data in the node in advance id.
Traverse when deleting tableID, According to the node id remove Drop all nodes , Then clear the line and the endpoint .

原网站

版权声明
本文为[mizuhokaga]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202160515546417.html