diff --git a/lib/backbone-pageable.js b/lib/backbone-pageable.js index 97734e5..c4c1b7e 100644 --- a/lib/backbone-pageable.js +++ b/lib/backbone-pageable.js @@ -93,7 +93,6 @@ var PARAM_TRIM_RE = /[\s'"]/g; var URL_TRIM_RE = /[<>\s'"]/g; - var BaseCollection = Backbone.Collection; /** Drop-in replacement for Backbone.Collection. Supports server-side and @@ -257,7 +256,7 @@ */ constructor: function (models, options) { - BaseCollection.apply(this, arguments); + BBColProto.constructor.apply(this, arguments); options = options || {}; @@ -685,7 +684,7 @@ var fullCollection = this.fullCollection; var handlers = this._handlers = this._handlers || {}, handler; if (mode != "server" && !fullCollection) { - fullCollection = this._makeFullCollection(options.models || []); + fullCollection = this._makeFullCollection(options.models || [], options); fullCollection.pageableCollection = this; this.fullCollection = fullCollection; var allHandler = this._makeCollectionEventHandler(this, fullCollection); diff --git a/test/client-pageable.js b/test/client-pageable.js index 2c04d55..96b574d 100644 --- a/test/client-pageable.js +++ b/test/client-pageable.js @@ -100,12 +100,12 @@ $(document).ready(function () { strictEqual(col.comparator, comparator); strictEqual(col.size(), 2); strictEqual(col.at(0).get("name"), "a"); - strictEqual(col.at(1).get("name"), "c"); + strictEqual(col.at(1).get("name"), "b"); strictEqual(col.fullCollection.size(), 3); strictEqual(col.at(0), col.fullCollection.at(0)); strictEqual(col.fullCollection.at(0).get("name"), "a"); - strictEqual(col.fullCollection.at(1).get("name"), "c"); - strictEqual(col.fullCollection.at(2).get("name"), "b"); + strictEqual(col.fullCollection.at(1).get("name"), "b"); + strictEqual(col.fullCollection.at(2).get("name"), "c"); mods = models.slice(); @@ -556,7 +556,7 @@ $(document).ready(function () { strictEqual(col.fullCollection.at(2).get("name"), "b"); strictEqual(col.fullCollection.at(3).get("name"), "a"); }); - + test("getPageByOffset - firstPage is 0", function () { var manyModels = [ {"name": "a1"}, @@ -808,4 +808,25 @@ $(document).ready(function () { strictEqual(col.hasNext(), false); }); + test("parsing from constructor #112", function () { + var Model = Backbone.Model.extend({ + parse: function (raw) { + return { value: raw } + } + }); + + var MyCollection = Backbone.PageableCollection.extend({ + model: Model, + mode: 'client', + state: { + firstPage: 0, + pageSize: 2 + } + }); + + var col = new MyCollection([1, 2, 3], {parse: true}); + deepEqual(col.toJSON(), [{"value": 1}, {"value": 2}]); + deepEqual(col.fullCollection.toJSON(), [{"value": 1}, {"value": 2}, {"value": 3}]); + }); + });