In the code below, I render 3 views. The second and third views render App.controller.a
. Clicking the first view changes App.controller.a
. As you click, the third view updates its content. The second view does not update its content. Why?
I presumed that the second view binds to the array App.controller.a
. It looks like the binding is not updating.
Demo: http://jsfiddle.net/kcmH4/
The code:
App = Ember.Application.create({});
App.controller = Ember.Object.create({
a: Ember.A([1]),
my_method: function() {
var a = this.get('a');
$.each([2], function(i, element) {
a.pushObject(element);
});
}
});
App.MyView = Ember.View.extend({
click: function() {
this.get('content').my_method();
}
});
The template:
{{#view App.MyView contentBinding="App.controller"}}
First view: Click me
{{/view}}
{{#view Ember.View contentBinding="App.controller"}}
2nd view: {{content.a}}
{{/view}}
{{#view Ember.View contentBinding="App.controller"}}
Third view:
<ul>
{{#each content.a}}
<li>{{this}}</li>
{{/each}}
</ul>
{{/view}}