Ember : addObject/ pushObject is not a function

2020-08-02 03:04发布

问题:

I recently moved from ember 1.x to 2.6. I am not able to use addObject/pushObject like i used to.

Ember      : 2.6.2
jQuery     : 2.2.4

import Ember from 'ember';

export default Ember.Controller.extend({
    test: ['sibi', 'john'],

    init: function() {
        this.get('test').pushObject('sebastian');
    }
});

This throws an error like pushObject is not a function. What is the workaround? Thank you.

回答1:

The extend prototypes option was false for some reason. You can read more about disabling prototype extensions in the guide.

EmberENV: {
      EXTEND_PROTOTYPES: {
        Array: true
      }
    }

Thank you!



回答2:

Check your package.json against ember-disable-prototype-extensions.

If your project is an addon project it had beed added by ember-cli. And you should live with it. (Use Ember.A whenever you need an Ember array.)

If your project is an application project, just remove this addon.