我添加了示例应用程序。 http://jsfiddle.net/Sly7/amG56/
JS:
App = Ember.Application.create();
App.ApplicationController = Ember.ArrayController.extend({
selectedBook: null
});
App.ApplicationView = Ember.View.extend({
actions: {
selectBook: function(book) {
this.get('controller').set("selectedBook", book);
},
cancel: function(book) {
alert(book);
}
}
});
App.Book = Em.Object.extend({
name: null
});
模板:
<script type="text/x-handlebars">
{{#each book in books}}
<a {{action "selectBook" book target="view"}} href="#">select {{book.name}}</a><br />
{{/each}}
<hr />
Selected Book: {{selectedBook.name}}
<br />
<a {{action "cancel" selectedBook target="view"}} href="#">cancel selected book</a>
</script>
</p>
选择其中一本书。您将看到将显示该书的名称。但是“取消选定的书”链接不起作用。
I think the problem is context of the action helper does not change when a book is selected.
如何实现具有不断变化的上下文的动作助手?或者它是一个错误?