jQuery Ui sortable can`t drag li elements in cloned ul

时光总嘲笑我的痴心妄想 提交于 2019-12-11 14:28:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!