ember-cli-pagination icon indicating copy to clipboard operation
ember-cli-pagination copied to clipboard

Cannot read property 'slice' of null

Open canufeel opened this issue 9 years ago • 14 comments

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. (http://127.0.0.1:4200/assets/vendor.js:85121:31) at Descriptor.ComputedPropertyPrototype.get (http://127.0.0.1:4200/assets/vendor.js:23900:26) at Object.get (http://127.0.0.1:4200/assets/vendor.js:29698:19) at _emberRuntimeSystemObject.default.extend._setupArrangedContent (http://127.0.0.1:4200/assets/vendor.js:46552:53) at _emberRuntimeSystemObject.default.extend.init (http://127.0.0.1:4200/assets/vendor.js:46708:12) at superWrapper as init at new Class (http://127.0.0.1:4200/assets/vendor.js:46854:14) at Function.ClassMixinProps.create (http://127.0.0.1:4200/assets/vendor.js:47290:14) at null. (http://127.0.0.1:4200/assets/vendor.js:84758:10)

Would appreciate any help.

canufeel avatar Jul 12 '15 04:07 canufeel

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);
  },

broerse avatar Jul 12 '15 15:07 broerse

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.

canufeel avatar Jul 12 '15 16:07 canufeel

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

broerse avatar Jul 12 '15 20:07 broerse

I just removed the ArrayController and this module keeps working without change.

https://github.com/broerse/ember-cli-blog/commit/2f9af92d9b2728d8f49a6868343cbdefbc606310

broerse avatar Jul 15 '15 20:07 broerse

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?

ptadros avatar Jul 21 '15 11:07 ptadros

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

dzena avatar Jul 30 '15 14:07 dzena

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

mharris717 avatar Aug 27 '15 15:08 mharris717

Did anybody solve this problem? Even with the latest release (0.9.0) the problem still exists.

psoladoye avatar Sep 10 '15 21:09 psoladoye

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 avatar Sep 16 '15 21:09 schmooie

@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 avatar Sep 17 '15 06:09 broerse

@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 avatar Sep 17 '15 13:09 schmooie

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

broerse avatar Sep 17 '15 19:09 broerse

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

vikram-s-narayan avatar Feb 25 '16 06:02 vikram-s-narayan

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"

dzena avatar May 04 '16 09:05 dzena