I can include an array in an Ember object, and display the contents using Handlebars. However, I can only replace the array contents using set(). How can I modify the array contents using push/pop/etc. and still have the UI bindings update?
// JS
App.obj = Ember.Object.create({
"things": ["1", "2"],
});
App.obj.set("things", ["1", "2", "3"]); // Works
App.obj.things.push("3"); // Doesn't Work
// HTML + Handlebars
{{#with App.obj}}
<ul>
{{#each things}}
<li>{{this}}</li>
{{/each}}
</ul>
{{/with}}
For working with collections, Ember.js provides an Array wrapper class, Ember.Array / Ember.MutableArray
So, instead of using a plain array, use these:
Use an instance of Ember.ArrayController,simply declaring an array with [] will also create array of Ember.ArrayController class.
If you want to add an Object at the end of Ember ArrayController you can use the addObject() method;
eg.