问题
i have a problem with a jQuery sortable list. I got two ul-lists. These two lists are sortable (the complete ul-sets) and the li children are sortable also. So you can sort the complete list position and you can sort the li-positions and drag li-elements from one list to another.
Using a button next to each list, i can clone a complete ul-list. Therefore i use the clone(true,true) function. I use true parameters, because i got events on the buttons and i want them to be applied to the clones. I also want the sortable function to be applied to the clone.
Problems:
+++++++++++++++++++++++++++++++++++++
When i only use clone()
to clone the element:
You cant drag the li Elements from the ul>-clone to another list and you can`t clone a cloned element twice with the clone-button (button action got lost).
When i use clone(true)
or clone(true,true)
to clone the element:
You can drag li-elements from the ul-clone to another list, but you can`t drag li-elements from other lists to the ul-clone.
You can try it out here:
http://jsfiddle.net/uKEJL/133/
Any Idea?
-Thx Tobi-
回答1:
Your problem has to do with bindings. The event callbacks get bound to the current widget object. Compare
https://github.com/jquery/jquery-ui/blob/master/ui/jquery.ui.mouse.js#L31-L41
If you clone the lists, the event gets fired correctly by jQuery, but the callback is bound to the original list.
You will have to initialize sortable on every clone.
来源:https://stackoverflow.com/questions/15497383/jquery-ui-sortable-cant-drag-li-elements-in-cloned-ul