Jquery 删除dblclick上的jsplump节点

Jquery 删除dblclick上的jsplump节点,jquery,jsplumb,Jquery,Jsplumb,我基本上需要3个按钮分别添加1个不同的元素(已经可以使用了),这些元素有起点和终点,当您双击一个元素时,我希望它删除整个元素和连接,这段代码可以: instance.detachAllConnections("Service1"); instance.remove("Service1"); 但是我不能让它在双击事件上工作。。。以下是迄今为止我得到的js代码: var instanceJsPlumb = null; jsPlumb.ready(funct

我基本上需要3个按钮分别添加1个不同的元素(已经可以使用了),这些元素有起点和终点,当您双击一个元素时,我希望它删除整个元素和连接,这段代码可以:

      instance.detachAllConnections("Service1");
      instance.remove("Service1");
但是我不能让它在双击事件上工作。。。以下是迄今为止我得到的js代码:

    var instanceJsPlumb = null;

    jsPlumb.ready(function () {

    var instance = jsPlumb.getInstance({
        DragOptions: {cursor: 'pointer', zIndex: 2000},

       ConnectionOverlays: [
           ["Arrow", {location: 1}],
       ],
      Container: "sem-dia"
    });

   instanceJsPlumb = instance;

   var basicType = {
         connector: "StateMachine",
       paintStyle: {strokeStyle: "red", lineWidth: 4},
       hoverPaintStyle: {strokeStyle: "blue"},
       overlays: [
        "Arrow"
     ]
  };
   instance.registerConnectionType("basic", basicType);


   var connectorPaintStyle = {
           lineWidth: 4,
           strokeStyle: "grey",
           joinstyle: "round",
           outlineColor: "white",
           outlineWidth: 2
       },

      connectorHoverStyle = {
          lineWidth: 4,
          strokeStyle: "#216477",
          outlineWidth: 2,
          outlineColor: "white"
      },
    endpointHoverStyle = {
        fillStyle: "#216477",
        strokeStyle: "#216477"
    },

    sourceEndpoint = {
        endpoint: "Dot",
        maxConnections: -1,
        paintStyle: {strokeStyle: "#7AB02C", fillStyle: "transparent", radius: 7, lineWidth: 3},
        isSource: true,
        connector: ["Flowchart", {stub: [40, 60], gap: 10, cornerRadius: 5, alwaysRespectStubs: true}],
         connectorStyle: connectorPaintStyle,
         hoverPaintStyle: endpointHoverStyle,
         connectorHoverStyle: connectorHoverStyle,
         dragOptions: {},
         overlays: [

        ]
    },
      targetEndpoint = {
         endpoint: "Dot",
         paintStyle: {fillStyle: "#7AB02C", radius: 11},
          hoverPaintStyle: endpointHoverStyle,
         maxConnections: -1, 
         dropOptions: {hoverClass: "hover", activeClass: "active"},
         isTarget: true,
         overlays: [
         ]
     },
     init = function (connection) {
     };

 var _addEndpoints = function (toId, sourceAnchors, targetAnchors) {

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

    instance.batch(function () {

      var dia = $("#sem-dia");
      var arr = [];
      $.each(components, function (i, component) {
          if(component.type === 'q'){
              arr.push("<div class='window questions' id='");

          }else{
              if(component.type === 'a'){
                 arr.push("<div class='window answers' id='");
              }else{
                  arr.push("<div class='window other' id='");
              }
          }
          arr.push(component.id);
          arr.push("' style='top: ");
          arr.push(component.y);
          arr.push("px; left: ");
          arr.push(component.x);
          arr.push("px;'> <strong>");
          arr.push(component.name);
          arr.push("</strong><br/><br/> </div>");
      });
      dia.append(arr.join(''));

      $.each(components, function (i, component) {
          _addEndpoints(component.id, ["BottomCenter"], ["TopCenter"]);
      });

      instance.bind("connection", function (connInfo, originalEvent) {
          init(connInfo.connection);
      });

      instance.draggable($("#sem-dia").find("div.window"), {grid: [20, 20]});

      $.each(links, function (i, link) {
          instance.connect({uuids: [link.src + "BottomCenter", link.dst + "TopCenter"],
              editable: true});

      });



      instance.bind("click", function (conn, originalEvent) {
          if (confirm("Delete connection from " + conn.sourceId + " to " + conn.targetId + "?"))
             instance.detach(conn);
              conn.toggleType("basic");
      });

      instance.bind("connectionDrag", function (connection) {
          console.log("connection " + connection.id + " is being dragged. suspendedElement is ", connection.suspendedElement, " of type ", connection.suspendedElementType);
      });

      instance.bind("connectionDragStop", function (connection) {
          console.log("connection " + connection.id + " was dragged");
      });

      instance.bind("connectionMoved", function (params) {
          console.log("connection " + params.connection.id + " was moved");
      }); 

      //This code in a function for any element with a dblclick event that pops an alert and if you press yes it deletes that node and his connections
        //instance.detachAllConnections("Service1");
        //instance.remove("Service1");
  });

       var cont=2;
   $("#botonNewService").mousedown(function(event) {
      var id = "Service" + cont ;
      cont++;
      $("#sem-dia").append("<div class='window other' id='" + id +
      "' style='top: 10em; left: 0em;'><strong>Añadir External Service</strong><br/><br/></div>");
      _addEndpoints(id, ["BottomCenter"], ["TopCenter"]);

      instance.draggable($("#"+id), {containment:true});
      instance.trigger($("#"+id), "mousedown");
      instance.trigger(document, "mousemove");
  });
      var cont2=2;
  $("#botonNewQuestion").mousedown(function(event) {
      var id2 = "Pregunta" + cont2 ;
      cont2++;
      $("#sem-dia").append("<div class='window questions' id='" + id2 +
    "' style='top: 20em; left: 0em;'><strong>Pregunta usuarios</strong><br/><br/></div>");
    _addEndpoints(id2, ["BottomCenter"], ["TopCenter"]);

    instance.draggable($("#"+id2), {containment:true});
    instance.trigger($("#"+id2), "mousedown");
    instance.trigger(document, "mousemove");
});
    var cont3=3;
$("#botonNewAnswer").mousedown(function(event) {
    var id3 = "Respuesta" + cont3;
    cont3++;
    $("#sem-dia").append("<div class='window answers' id='" + id3 +
    "' style='top: 30em; left: 0em;'><strong>Respuesta sistema</strong><br/><br/></div>");
    _addEndpoints(id3, ["BottomCenter"], ["TopCenter"]);

    instance.draggable($("#"+id3), {containment:true});
    instance.trigger($("#"+id3), "mousedown");
    instance.trigger(document, "mousemove");
});


jsPlumb.fire("jsPlumbLoaded", instance);

 });

   $("#botonSave").click(function(){
var components_save = [];
$("#sem-dia").find("div.window").each(function (index) {
    var type = "o";
    if($(this).hasClass("questions")){
        type = "q";
    }else{
        if($(this).hasClass("answers")){
            type = "a";
        }
    }
    var position = $(this).position();
    components_save.push({"id": $(this).attr( "id"), "name": $(this).find("strong").text(), "type": type,
        "x": position.left, "y": position.top})
});

var links_save = [];
if(instanceJsPlumb != null){
    $.each(instanceJsPlumb.getAllConnections(), function (i, connection) {
        links_save.push({"src": connection.sourceId, "dst": connection.targetId})
    });
}

$("#result").text(JSON.stringify({"components":components_save, "links":links_save}))
 });
var instanceJsPlumb=null;
jsPlumb.ready(函数(){
var instance=jsPlumb.getInstance({
DragOptions:{cursor:'pointer',zIndex:2000},
连接概述:[
[“箭头”{位置:1}],
],
容器:“扫描电镜直径”
});
instanceJsPlumb=实例;
变量基本类型={
连接器:“状态机”,
画风:{strokeStyle:“红色”,线宽:4},
悬停画风:{strokeStyle:“蓝色”},
覆盖层:[
“箭头”
]
};
registerConnectionType(“基本”,basicType);
变量connectorPaintStyle={
线宽:4,
strokeStyle:“灰色”,
joinstyle:“圆形”,
大纲颜色:“白色”,
大纲图第1页第2页
},
connectorHoverStyle={
线宽:4,
strokeStyle:#216477“,
大纲第1页第2页,
大纲颜色:“白色”
},
端点悬停样式={
填充样式:“216477”,
strokeStyle:#216477"
},
sourceEndpoint={
端点:“点”,
maxConnections:-1,
画风:{strokeStyle:#7AB02C],fillStyle:“透明”,半径:7,线宽:3},
来源:是的,
连接器:[“流程图”{stub:[40,60],间隙:10,转弯半径:5,alwaysRespectStubs:true}],
connectorStyle:connectorPaintStyle,
hoverPaintStyle:endpointHoverStyle,
connectorHoverStyle:connectorHoverStyle,
dragOptions:{},
覆盖层:[
]
},
targetEndpoint={
端点:“点”,
画风:{fillStyle:#7AB02C',半径:11},
hoverPaintStyle:endpointHoverStyle,
maxConnections:-1,
dropOptions:{hoverClass:“hover”,activeClass:“active”},
isTarget:没错,
覆盖层:[
]
},
init=函数(连接){
};
var _addEndpoints=函数(toId、源锚点、目标锚点){
对于(var i=0;iarr.push(“您可以使用
id=“target”
双击删除jsplump元素,如下所示:

$("#target").dblclick(function() {
  instance.remove($(this));
});

其中
instance=jsPlumb.getInstance(…

您可以通过如下方式双击来删除带有
id=“target”
的jsPlumb元素:

$("#target").dblclick(function() {
  instance.remove($(this));
});

其中
instance=jsPlumb.getInstance(…

您可以通过如下方式双击来删除带有
id=“target”
的jsPlumb元素:

$("#target").dblclick(function() {
  instance.remove($(this));
});

其中
instance=jsPlumb.getInstance(…

您可以通过如下方式双击来删除带有
id=“target”
的jsPlumb元素:

$("#target").dblclick(function() {
  instance.remove($(this));
});

其中
instance=jsPlumb.getInstance(…

因为元素是动态创建的。每次创建新元素时,都必须为每个元素显式添加
dblclick
处理程序。另一种方法(更好)是在
文档上附加
dblclick
,如下所示:

$(document).on('dblclick','.window',function(){
    instance.remove($(this));
    //other logic goes here...
});

由于元素是动态创建的。每次创建新元素时,都必须显式添加
dblclick
处理程序。另一种方法(更好)是在
文档上附加
dblclick
,如下所示:

$(document).on('dblclick','.window',function(){
    instance.remove($(this));
    //other logic goes here...
});

由于元素是动态创建的。每次创建新元素时,都必须显式添加
dblclick
处理程序。另一种方法(更好)是在
文档上附加
dblclick
,如下所示:

$(document).on('dblclick','.window',function(){
    instance.remove($(this));
    //other logic goes here...
});

由于元素是动态创建的。每次创建新元素时,都必须显式添加
dblclick
处理程序。另一种方法(更好)是在
文档上附加
dblclick
,如下所示:

$(document).on('dblclick','.window',function(){
    instance.remove($(this));
    //other logic goes here...
});
将#target替换为.window适用于我在data.js上已经拥有的元素,但它不会删除我用按钮创建的元素,知道为什么吗?它们应该是所有的窗口类…将#target替换为.window适用于我在data.js上已经拥有的元素,但它不会删除我用按钮创建的元素ns,有什么线索吗?它们应该是所有窗口类…用.window替换#target。window适用于我已经在data.js上拥有的元素,但它不会删除我用按钮创建的元素,有什么线索吗?它们应该是所有窗口类…用.window替换#target。window适用于我已经在data.js上拥有的元素.js但它不会删除我用按钮创建的那些,有什么线索吗?它们应该都是窗口类。。。