Comments (6)
Also, note that simply adding an item does not cause this problem. It's only after it's moved that the output becomes incorrect.
Using the mapping plugin directly on the items array instead of its containing object when initializing the viewModel fixes this problem. This is pretty much the same "fix" as before, except doing it first instead of last. Here's the updated example: http://jsfiddle.net/WDrep/6/
I was hoping to use the mapping plugin once on the data received from the server and not on each property individually. This normally works fine, but seems to create problems using the mapping and sorting plugins together.
Thanks again,
Bill
from knockout-sortable.
@wjbryant I'll see if I can take a closer look when I get a chance. It appears that it is related to the mapping plugin.
If you take sortable out of the picture and add an item, then do something like:
var items = viewModel.data.items,
item = items()[3];
items.remove(item);
items.splice(2, 0, item);
You will see the same behavior.
from knockout-sortable.
@rniemeyer Thanks for the insight. I guess it's a mapping bug then. You don't even have to remove the item, just using splice to insert any item but the last one has the same effect. Here is an updated and simplified example that I think better demonstrates this: http://jsfiddle.net/WDrep/9/
from knockout-sortable.
I think that the best course of action is to open an issue with the mapping plugin. If it turns out that there is something that this plugin can do to help compensate for it, then I would be happy to look at including some changes for it.
from knockout-sortable.
This is the related knockout-mapping issue: SteveSanderson/knockout.mapping#74
from knockout-sortable.
The solution from the knockout-mapping issue was to use the create
callback to keep everything in sync. I'm not sure why it makes a difference, but it fixes the problem.
Here is an example of this working with the sortable plugin: http://jsfiddle.net/WDrep/11/
from knockout-sortable.
Related Issues (20)
- observableArray extended with deferred: true removes items from list HOT 2
- Draggable Incorrectly calls template init/update
- Using droppable next to a sortable
- Draggable Droppable Issue
- sortable dissapears after first drop HOT 4
- knockout-sortable not re-rendering when dragging to same index
- Sortable not working with latest jquery HOT 3
- Input and textarea cannot be selected in Firefox 40
- sortable behaviour inconsistent with droppable/draggable
- Confirmation popup before aftermove is executed HOT 1
- Sortable not working after upgrading to knockout 3.5 HOT 10
- anonymous templates will break in next version of knockout HOT 3
- droppable options drop event issue
- Does not work with knockout 3.5.0 HOT 2
- Problem after upgrading ko to 3.5.1 HOT 3
- Nested sortable support
- knockout-sortable drag and drop not working in Windows touch devices
- Get an error after clean data HOT 3
- JS error introduced by v1.2.1 "Fixed draggable and droppable disposal" HOT 1
- disableSelection on sortable
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from knockout-sortable.