Skip to content
This repository has been archived by the owner on May 17, 2018. It is now read-only.

When adding models through collection.add([]) (passed as array) some models are missing #43

Closed
fredipevcin opened this issue Feb 13, 2013 · 1 comment

Comments

@fredipevcin
Copy link

When adding models through collection.add([]) (passed as array) fullCollection is missing some models. If i add them one by one works like it's supposed to.

Using:

  • Backbone.js 0.9.10/0.9.9
  • Underscore.js 1.4.4
  • Backbone-pageable 1.1.5

Example:

var TestModel = Backbone.Model.extend({})
var TestCollection = Backbone.PageableCollection.extend({
    model: TestModel,

    mode: "client",

    state: {
        firstPage: 0,
        currentPage: 0,
        pageSize: 3
    },

    comparator: function (model) {
        return model.get("name");
    }
})

var data = [
{
    id: "1",
    name: "test3"
},{
    id: "2",
    name: "test5"
},{
    id: "3",
    name: "test1"
},{
    id: "4",
    name: "test2"
},{
    id: "5",
    name: "test4"
},{
    id: "6",
    name: "test6"
},{
    id: "7",
    name: "test7"
},{
    id: "8",
    name: "test8"
}
];
var collection = new TestCollection();
collection.add(data);


console.log("data: ", _.pluck(data, "name"));
console.log("collection: ", collection.pluck("name"));
console.log("fullCollection: ", collection.fullCollection.pluck("name"));

collection.getNextPage();
console.log("collection (nextPage 1): ", collection.pluck("name"));

collection.getNextPage();
console.log("collection (nextPage 2): ", collection.pluck("name"));

Output

data:  ["test3", "test5", "test1", "test2", "test4", "test6", "test7", "test8"]
collection:  ["test1", "test2", "test3"]
fullCollection:  ["test1", "test2", "test3", "test4", "test5"]
collection (nextPage 1):  ["test4", "test5"]
Uncaught RangeError: `currentPage` must be firstPage <= currentPage < totalPages if 0-based. Got 2. 
@wyuenho
Copy link
Member

wyuenho commented Feb 13, 2013

Mmmm strange. Adding one by one and en-mass shouldn't make any difference as the event handlers are triggered for each time a new model is added anyway.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants