ember newjack here. Hooking an ArrayController into a CollectionView.
// the ArrayController
App.Entities = Ember.ArrayController.create({
content: Ember.A([
{id: 1, name: "item 1"},
{id: 2, name: "item 2"},
...
{id: n, name: "item n"}
])
});
// the CollectionView
myView = Ember.CollectionView.create(
contentBinding: "App.Entities",
tagName: 'ul',
itemViewClass: Ember.View.extend({
template: Ember.Handlebars.compile('{{view.content.name}}')
})
).appendTo("mySelector");
Which, as expected creates a nice ul with my properties.
As well, all array-level operations such as popping, pushing and reversing work fabulously:
App.Entities.reverseObjects(); // Works!
App.Entities.popObject(); // Works!
However, I can’t seem to update a property inside the array:
App.Entities.objectAtContent(0).name = "new name" // I know this is wrong
Anecdotally, it works if I perform an array operation afterwards:
App.Entities.reverseObjects(); // change is picked up!
So the question: How to update properties INSIDE an ArrayController (And make sure bindings are updated?)
By the way, I’ve tried everything I can think of.. such as myView.rerender() etc but I know I’m just doing something wrong because it’s going against the way things should work.
Try
App.Entities.objectAt(0).set('name', "New name")and let me know if this works…The Array must contain Ember Objects in order for the bindings to work for the changes made