using a draggable as a source list links items add

2019-07-24 20:27发布

问题:

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/