Giter Site home page Giter Site logo

Comments (6)

wjbryant avatar wjbryant commented on August 17, 2024

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.

rniemeyer avatar rniemeyer commented on August 17, 2024

@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.

wjbryant avatar wjbryant commented on August 17, 2024

@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.

rniemeyer avatar rniemeyer commented on August 17, 2024

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.

wjbryant avatar wjbryant commented on August 17, 2024

This is the related knockout-mapping issue: SteveSanderson/knockout.mapping#74

from knockout-sortable.

wjbryant avatar wjbryant commented on August 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.