親テンプレート内のプロパティの変更について簡単な質問がありました。私が書いたコードは以下のとおりです。
App.Router.map(function () {
this.resource('parent' , { path: "/parent" }, function() {
this.route('child1');
this.route('child2');
this.route('child3');
});
このルーターは、次のルートを作成します。
- 親
- 親.index
- 親.子1
- 親.子2
- 親.子3
以下は私のテンプレートです(簡略化)
<script type="text/x-handlebars" data-template-name="application">
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="parent">
<h1>{{title}}</h1>
Common html
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="parent/index">
Parent specific content
</script>
<script type="text/x-handlebars" data-template-name="parent/child1">
Child 1 specific content
</script>
<script type="text/x-handlebars" data-template-name="parent/child2">
Child 2 specific content
</script>
<script type="text/x-handlebars" data-template-name="parent/child3">
Child 3 specific content
</script>
そして、ここに私のコントローラーがあります
App.ParentController = Ember.Controller.extend({
title: 'Parent Title'
});
App.ParentIndexController = Ember.Controller.extend({
title: 'Parent Index Title'
});
App.Child1Controller = Ember.Controller.extend({
title: 'Child 1 Title'
});
App.Child2Controller = Ember.Controller.extend({
title: 'Child 2 Title'
});
App.Child3Controller = Ember.Controller.extend({
title: 'Child 3 Title'
});
子コントローラー内にいるときに、template="parent" 内の {{title}} プロパティを更新するにはどうすればよいですか? 私はこのようなことを試しました
App.Child3Controller = Ember.Controller.extend({
needs: ['parent'],
init: function() {
this.get('controllers.parent').set('title', 'Child 3 Title');
}
});
ただし、親テンプレートは更新しません。では、どうすればこれを達成できますか?