ember-cli-pagination
ember-cli-pagination copied to clipboard
Cannot read property 'slice' of null
I am not sure if i setup this addon as it is expected. However there is very little explanation on what should be put as first argument to the pagedArray
Here is my code:
controllers/index.js
export default Ember.Controller.extend({
records: Ember.computed.alias('model.records'),
queryParams: ["page", "perPage"],
page: 1,
perPage: 20,
pagedContent: pagedArray('records',
{
pageBinding: "page",
perPageBinding: "perPage"
}),
totalPagesBinding: "pagedContent.totalPages",
selectedCategory: null,
actions: {
// code omitted
}
});
routes/index.js
export default Ember.Route.extend({
model: function() {
return Ember.RSVP.hash({
categories: this.store.findAll('category'),
records: this.store.findAll('record')
})
}
});
I get this error:
Error while processing route: index Cannot read property 'slice' of null TypeError: Cannot read property 'slice' of null
at exports.default.Ember.default.Object.extend.objsForPage (http://127.0.0.1:4200/assets/vendor.js:84799:29)
at null.
Would appreciate any help.
Perhaps add something like this to your routes:
setupController: function(controller, models) {
var categories = models.categories;
var records = models.records;
this.controllerFor('index').set('categories', categories);
this.controllerFor('index').set('records', records);
},
That was my first thought. i have added the following to my route:
setupController: function(controller,model) {
controller.set('categories',model.categories);
controller.set('records',model.records);
}
And changed the
pagedContent: pagedArray('records',
{
pageBinding: "page",
perPageBinding: "perPage"
}),
to be
pagedContent: pagedArray('records.content',
{
pageBinding: "page",
perPageBinding: "perPage"
}),
I have checked and when i select this controller in the ember inspector and do $E.records.content
it actually points to the records array. but the same error still shows up.
I believe that the problem is in fact is in the: addon/computed/paged-array.js on line 24
var paged = PagedArray.extend({
contentBinding: "parent."+contentProperty
}).create(pagedOps);
// paged.lockToRange();
return paged;
The contentBinding
here becomes parent.records.content
. This PagedArray class is a subclass of Ember.ArrayProxy
but neither of them seems to actually access this contentBinding argument ever.
I think you must only write records
see:
https://github.com/broerse/ember-cli-blog/blob/master/app/routes/posts.js
but I am also in the middle of removing the ArrayController
I just removed the ArrayController and this module keeps working without change.
https://github.com/broerse/ember-cli-blog/commit/2f9af92d9b2728d8f49a6868343cbdefbc606310
I have the same problem. Can anyone give an examples of json response and how to customize if the key's name is different than default name in the add-on?
@canufeel Did anybody solved the problem. I have a pretty simple configuration:
records: Ember.computed.alias("model"), queryParams: ["page", "perPage"], page: 1, perPage: 3, pagedContent: pagedArray('records', { pageBinding: "page", perPageBinding: "perPage" }), totalPagesBinding: "pagedContent.totalPages"
yet I get the same error.
@canufeel @dzena if you get a chance, could you test with 0.9.0 and let me know if you are still having an issue?
Did anybody solve this problem? Even with the latest release (0.9.0) the problem still exists.
Has anyone been able to resolve this issue? I've just updated to 0.9.0 and it's still breaking for me.
author: Ember.computed.alias('model'),
articles: Ember.computed.alias('author.articles'),
queryParams: ['page', 'perPage'],
page: 1,
perPage: 10,
pagedContent: pagedArray('articles', {
pageBinding: 'page',
perPageBinding: 'perPage'
}),
totalPagesBinding: 'pagedContent.totalPages',
I've also tried setting the articles
property in my route like others have suggested.
setupController(controller, model) {
controller.set('articles', model.get('articles'));
}
@schmooie If you are on Ember 1.13.7 try switching to Ember 1.13.8. It fixes many things. I don't know if it will fix this. @mharris717 if Ember 1.13.8 does not help how can we best reproduce this issue? I like to take a look.
@broerse I've bumped up my Ember version from 1.13.3 to 1.13.7 and then to 1.13.8, still no dice.
@schmooie How can we see this bug. Is it perhaps possible to submit the issue as PR to https://github.com/broerse/ember-cli-blog ?
I got the same issue today when I tried to pass the model through the controller on Ember 1.13.11. Workaround was to do what @broerse has done(https://github.com/broerse/ember-cli-blog) and pass the model to a component. Links to relevant code below:
ember-cli-blog/app/templates/posts.hbs ember-cli-blog/app/templates/components/blog-posts.hbs ember-cli-blog/app/controllers/posts.js ember-cli-blog/app/components/blog-posts.js
In each controller where you use this add-on:
memberships: Ember.computed("model.[]", function () {
var memberships = this.get("model");
if (memberships !== null) {
return memberships;
} else {
return [];
}
}),
queryParams: ["page", "perPage"],
page: 1,
perPage: 2,
pagedContent: pagedArray('memberships', {
pageBinding: "page",
perPageBinding: "perPage"
}),
totalPagesBinding: "pagedContent.totalPages"