使用可拖动作为源列表将添加到可排序项的项目链接在一起? [英] using a draggable as a source list links items added to a sortable together?

查看:89
本文介绍了使用可拖动作为源列表将添加到可排序项的项目链接在一起?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请原谅被黑的样本

http://jsfiddle.net/marcmeans/SqrBf/1/

如果将可用学生中的一项添加到Table3中两次,然后尝试将其中一项从Table3中移动到Table2中,则两者都会消失.

If you add an item from the available students to Table3 twice and then try and move one from Table3 to Table2, both disappear.

我还注意到,当我为添加到Table3的项目生成新的Guid时,arg.item似乎是对源列表中项目的引用,而不是克隆.这会在淘汰赛中创建一个链接,如果我更新其中的链接,则会全部更新.

I note as well that when I'm generating a new guid for the item added to Table3, the arg.item seems be a reference to the item in the source list and not a clone. This creates a link in knockout where if I update one I update them all.

我以为我在这里做错了什么,但是我很难找出原因.

I'm assuming that I am doing something wrong here, but I'm having a hard time figuring out what.

推荐答案

sortable插件中的draggable功能当前检查对象是否具有clone功能.如果是这样,那么它将使用调用clone的结果作为新项.如果不是,那么它将使用项目本身.

The draggable functionality in the sortable plugin currently checks to see if your object has a clone function on it. If it does, then it uses the result of calling clone as the new item. If not, then it uses the item itself.

在您的小提琴中,您正在使用映射插件,因此一种选择是传递映射选项,以通过添加clone方法来自定义学生的创建方式.

In your fiddle, you are using the mapping plugin, so one option would be to pass mapping options that customize how your students are getting created by adding a clone method.

这里是一个更新的小提琴,它通过执行映射选项并通过执行ko.mapping.fromJS(ko.mapping.toJS(this))

Here is an updated fiddle that passes the mapping options and clones the object just by doing ko.mapping.fromJS(ko.mapping.toJS(this))

http://jsfiddle.net/rniemeyer/SqrBf/3/

这篇关于使用可拖动作为源列表将添加到可排序项的项目链接在一起?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆