using a draggable as a source list links items added to a sortable together?

为君一笑 提交于 2020-02-05 05:01:32

问题


excuse the hacked together sample

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

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

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.


回答1:


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.

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.

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/



来源:https://stackoverflow.com/questions/12517273/using-a-draggable-as-a-source-list-links-items-added-to-a-sortable-together

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