使用 jquery sortable 时如何复制项目?
I am using this method http://jqueryui.com/demos/sortable/#connect-lists to connect two lists that i have. I want to be able to drag from list A to list B but when the item is dropped, i need to keep the original one still in list A. I checked the options and events but I believe there is nothing like that. Any approaches?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
首先,看看这个,并阅读 @Erez 答案。
For a beginning, have a look at this, and read @Erez answer, too.
埃雷兹的解决方案对我有用,但我发现它缺乏封装,令人沮丧。我建议使用以下解决方案来避免全局变量的使用:
这是一个 jsFiddle: http://jsfiddle.net/v265q/190/< /a>
Erez' solution works for me, but I found its lack of encapsulation frustrating. I'd propose using the following solution to avoid global variable usage:
Here's a jsFiddle: http://jsfiddle.net/v265q/190/
我知道这已经过时了,但我无法得到埃雷兹的工作答案,而托尔斯滕的答案也没有适合我需要的项目。这似乎完全符合我的需要:
I know this is old, but I could not get Erez's answer to work, and Thorsten's didn't cut it for the project I need it for. This seems to work exactly how I need:
Abuser2582707 的答案最适合我。
除了一个错误:您需要将返回更改为
所以它应该是:
The answer of abuser2582707 works best for me.
Except one error: You need to change the return to
So it should be:
当使用 Erez 的解决方案但连接 2 个可排序的 portlet 时(基础是来自 http://jqueryui.com 的 portlet 示例代码/sortable/#portlets),克隆上的切换将不起作用。我在“return li.clone();”之前添加了以下行使其发挥作用。
这花了我一段时间才弄清楚,所以我希望它对某人有所帮助。
When using Erez's solution but for connecting 2 sortable portlets (basis was the portlet example code from http://jqueryui.com/sortable/#portlets), the toggle on the clone would not work. I added the following line before 'return li.clone();' to make it work.
This took me a while to figure out so I hope it helps someone.