我正在尝试从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)
答案 0 :(得分:1)
我在这篇文章中找到了答案:https://groups.google.com/forum/#!topic/jsplumb/Hsf6oKQiBt4
我只需要这一行代码:
instance.removeAllEndpoints(divId)
答案 1 :(得分:0)
这是另一个不需要实例的:
jsPlumb.removeAllEndpoints("divId");
答案 2 :(得分:0)
在这个片段中:
jsPlumb.removeAllEndpoints("divId")
实际发生的是您在 jsPlumb 的“默认”实例上调用该方法,该实例的存在是 jsPlumb 早期的遗留问题。在 jsPlumb 的“默认”实例上调用 removeAllEndpoints
不会影响您创建的任何其他实例。
在 4.x 中,jsPlumb 的这个“默认”实例不再存在。