以下のコードでは、3 つのビューをレンダリングします。2 番目と 3 番目のビューはレンダリングしますApp.controller.a
。最初のビューをクリックすると変更されますApp.controller.a
。クリックすると、3 番目のビューの内容が更新されます。2 番目のビューはそのコンテンツを更新しません。なんで?
2 番目のビューが array にバインドされていると想定しましたApp.controller.a
。バインディングが更新されていないようです。
デモ: http://jsfiddle.net/kcmH4/
コード:
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();
}
});
テンプレート:
{{#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}}