Skip to content
This repository was archived by the owner on May 17, 2018. It is now read-only.
This repository was 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

@fredipevcin

Description

@fredipevcin

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. 

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions