2010-12-12 26 views
8

我使用jQuery UI鏈接一些名單,並允許項目被拖動和不同列表之間下降了一個聰明的辦法。有獲得排序目標jQueryUI的

receive情況下,我想獲得該項目在下跌名單。是ui.item.parent()做正確的方式,或者是那裏uievent這將讓我直接訪問這個屬性?


<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

不,沒有直接的財產爲新的父(因爲.parent()是很容易的可能),那麼你有什麼是正確的。 You can view all the ui properties here

如果你想.closest(),第二父母,等等...這是更好地離開UI渺茫,因爲他們都是很容易的遍歷到;這也節省了直接在ui對象上提供參考的費用。

+0

大,感謝在清除了。有點困擾我,但我想我會克服它! – Armand 2010-12-12 03:46:38

+0

@Alison - 歡迎:) – 2010-12-12 03:48:09

6

由於在接收列表上調用了recieve事件,因此您可以通過$(this)獲取新父項。源列表可通過ui.sender訪問。

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

雖然很有趣。 ui.sender在update()方法上爲null。 – 2017-05-23 03:06:10