Given a controller in ember:
export default Ember.Controller.extend({
stringProp: "",
arrayProp: []
});
You can, for example, set the string property with this.set('stringProp', "Blah blah")
. But that is overriding. What I want to do is push to the array property.
Is there a better (either shorter or faster) way than this:
this.set('arrayProp', this.get('arrayProp').push(element));
Also, is there a shortcut for removing elements from such an array property?
Given a controller in ember:
export default Ember.Controller.extend({
stringProp: "",
arrayProp: []
});
You can, for example, set the string property with this.set('stringProp', "Blah blah")
. But that is overriding. What I want to do is push to the array property.
Is there a better (either shorter or faster) way than this:
this.set('arrayProp', this.get('arrayProp').push(element));
Also, is there a shortcut for removing elements from such an array property?
Share Improve this question edited Aug 6, 2015 at 12:14 user663031 asked Aug 6, 2015 at 9:54 Marco PrinsMarco Prins 7,41913 gold badges47 silver badges79 bronze badges1 Answer
Reset to default 21You are looking for pushObject
, removeObject
, etc. See http://emberjs.com/api/classes/Ember.MutableArray.html.
this.get('arrayProp').pushObject(element);
For correct behavior by computed properties and observers, it is strongly recommended you use these methods instead of push
or other native Array methods.