2017-08-07 43 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); 
     } 
    } 
});