从 div 中删除所有 jsPlumb 端点

Removing all jsPlumb endpoints from a div

我正在尝试从 div 中删除所有 jsPlumb 端点,源端点在右边,目标在左边。

这是将端点添加到 div 的代码:

addEndpointsToDiv("exp1", ["Right"], ["Left"])

function addEndpointsToDiv(divId, sourceAnchors, targetAnchors) {
for (var i = 0; i < sourceAnchors.length; i++) 
{
 var sourceUUID = divId + sourceAnchors[i];
 instance.addEndpoint(divId, sourceEndpoint, 
  {
    anchor: sourceAnchors[i], uuid: sourceUUID
  });
}
for (var j = 0; j < targetAnchors.length; j++) 
 {
 var targetUUID = divId + targetAnchors[j];
 instance.addEndpoint(divId, targetEndpoint, { anchor: targetAnchors[j], uuid: targetUUID });
 }
};

问题:如何从一个 div 中删除所有这些端点?

以下是我的一些失败尝试:

尝试 #1:

instance.deleteEndpoint(divId)

尝试#2

var endpoint = instance.getEndpoint(divId)
while (endpoint != null)
{
  instance.deleteEndpoint(divId)
  endpoint = instance.getEndpoint(divId)
}

尝试 #3

var endPoints = instance.selectEndpoints(divId)
endPoints.each(function (endpoint) {
instance.deleteEndpoint(endPoint)
});

尝试 #4

var endpoints = instance.getendpoints(divid)
for (endpoint in endpoints)
   instance.deleteendpoint(endpoint.endpoint)

我在这个 post 上找到了答案:https://groups.google.com/forum/#!topic/jsplumb/Hsf6oKQiBt4

我只需要这一行代码:

instance.removeAllEndpoints(divId)

这是另一个不需要实例的:

jsPlumb.removeAllEndpoints("divId");

在此代码段中:

jsPlumb.removeAllEndpoints("divId")

实际发生的是您在 jsPlumb 的“默认”实例上调用该方法,它的存在是 jsPlumb 早期的后遗症。在 jsPlumb 的“默认”实例上调用 removeAllEndpoints 不会影响您创建的任何其他实例。

在 4.x 中,jsPlumb 的这个“默认”实例不再存在。