是否有一种聪明的方法来获取jQueryUI中的可排序目标 [英] Is there a clever way of getting the sortable target in jQueryUI
问题描述
我正在使用jQuery UI链接许多列表,并允许在不同列表之间拖放项目.
I'm using jQuery UI to link a number of lists, and allow items to be dragged and dropped between the different lists.
在receive
事件中,我想获取放入该项目的列表.ui.item.parent()
是执行此操作的正确方法,还是存在ui
或event
的属性,我可以直接访问吗?
In the receive
event, I want to get the list that the item is dropped in. Is ui.item.parent()
the correct way to do that, or is there a property of ui
or event
which will let me 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();
}
});
推荐答案
不,新父级没有直接属性(因为您可以在此处查看所有ui
属性.
Nope, there's no direct property for the new parent (because .parent()
is easy enough probably), so what you have is correct. You can view all the ui
properties here.
如果您想要.closest()
,第二个父级,等等...最好让UI保持苗条,因为它们都很容易遍历;这也节省了直接在ui
对象上提供引用的费用.
If you wanted .closest()
, the second parent, etc...it's better to leave the UI slim since they're all easy enough to traverse to; this also saves the expense of providing the references directly on the ui
object.
这篇关于是否有一种聪明的方法来获取jQueryUI中的可排序目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!