2017-08-07 47 views
1

我正在使用JointJS创建动态图。在我的场景中,我收到了两篇论文。左边的包含元素形状作为模板,我可以将其拖放到正确的纸张上。一切都很好。但是现在我想把一个元素形状放在另一个元素上(例如一个耦合元素)。如果左侧元素与右侧纸张上的任何其他元素相交,则会触发一个事件,将新元素形状嵌入到现有元素中。提前如何删除元素并嵌入到关节中

... 

//try to embed by dropping 
_.each(graph.getElements(), function (el) { 
    if (el.getBBox().intersect(cellView.model.getBBox())) { 
     //embed element one into element two 
    } 
}); 

... 

感谢:

我得到这个至今,但路口不行!

回答

0

现在我要回答我的问题....

//get all existing elements and iterate through 
_.each(graph.getElements(), function (elements) { 
    //let s be the new element to drag over the parent element 
    if (s.getBBox().intersect(elements.getBBox())) { 
     //add a condition if you want.... 
     if (elements instanceof joint.shapes.devs.Coupled) { 
      //now embed the new element into the existing one 
      elements.embed(s); 
     } 
    } 
});