Is there any reasonable way to get a sortable target in jQueryUI

I use jQuery UI to link multiple lists and allow drag and drop items between different lists.

In the receive event, I want to get the list that the item fell into. Is ui.item.parent() correct way, or is there a ui or event property that allows me to access this directly?


 <ul><li>item 1</li></ul> <ul><li>item 2</li></ul> 

 $('ul').sortable({ connectWith: 'ul', receive: function(event, ui) { var targetList = ui.item.parent(); } }); 
+8
jquery jquery-ui-sortable
source share
2 answers

No, there is no direct property for the new parent (because .parent() is easy enough), so what you have is correct. Here you can view all ui properties .

If you want .closest() , the second parent, etc., it is better to leave the user interface thin, as they are all light enough to go through; it also saves the cost of providing links directly to the ui object.

+8
source share

Since the recieve event is recieve in the receiving list, you can get the new parent $(this) . The list of sources is available through ui.sender .

 $('ul').sortable({ connectWith: 'ul', receive: function(event, ui) { var sourceList = ui.sender; var targetList = $(this); } }); 
+6
source share

Source: https://habr.com/ru/post/650064/


All Articles