私たちは Ember アプリを構築しており、ネストされたビューを多数使用していますが、これまでのところ、1 つの問題を除いてすべてうまくいっています。ネストされたビューの 1 つにアクションを実装しようとすると、問題が発生します。
問題のビューは次のとおりです。
App.TodoView = Ember.View.extend({
templateName: 'app/templates/todo'
});
App.Todo_entriesView = Ember.View.extend({
templateName: 'app/templates/todo_entries'
});
App.Todo_entryView = Ember.View.extend({
templateName: 'app/templates/todo_entry',
});
テンプレートは次のとおりです。
/templates/todo.hbs
<article>
<h1>{{title}}</h1>
{{outlet}}
</article>
/templates/todo_entries.hbs
{{#if isLoading}}
<p>Loading...</p>
{{else}}
<ul class="list">
{{collection contentBinding="content" itemViewClass="App.Todo_entryView"}}
</ul>
{{/if}}
/templates/todo_entry.hbs
<li>
{{#if isLoading}}
Loading...
{{else}}
{{view.content.id}}) {{view.content.title}}
<a {{action deleteRecord href="true" target="controller"}}>Delete</a>
{{/if}}
</li>
コントローラーは次のとおりです。
App.TodoController = Ember.ObjectController.extend({
deleteRecord: function() {
this.get('content').deleteRecord();
this.transaction.commit();
App.router.transitionTo('todo');
}
});
App.Todo_entriesController = Ember.ArrayController.extend();
App.Todo_entryController = Ember.ObjectController.extend({
deleteRecord: function() {
this.get('content').deleteRecord();
this.transaction.commit();
App.router.transitionTo('todo');
}
});
削除ボタンをクリックすると、予想どおり、deleteRecord メソッドが Todo_entriesController (つまり、ビューの親) に存在せず、Todo_entryController にも存在しないというエラーが発生します。
Todo_entry テンプレートの deleteRecord アクションを取得して、Todo_entryController の deleteRecord メソッドを正しく呼び出す方法を知っている人はいますか? または、これを完全に行うためのより良い方法はありますか?
ありがとう、ダン