【问题标题】:Removing all jsPlumb endpoints from a div从 div 中删除所有 jsPlumb 端点
【发布时间】:2015-05-12 16:01:23
【问题描述】:

我正在尝试从 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)

【问题讨论】:

    标签: javascript html jsplumb


    【解决方案1】:

    我在这篇文章中找到了答案:https://groups.google.com/forum/#!topic/jsplumb/Hsf6oKQiBt4

    我只需要这行代码:

    instance.removeAllEndpoints(divId)
    

    【讨论】:

      【解决方案2】:

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

      jsPlumb.removeAllEndpoints("divId");
      

      【讨论】:

        【解决方案3】:

        在这个sn-p中:

        jsPlumb.removeAllEndpoints("divId")
        

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

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2013-04-26
          • 1970-01-01
          • 1970-01-01
          • 2013-08-07
          • 2014-01-29
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多