页面模板中的操作交互按钮,默认指向该模板对应的控制器。当然也可以指向相对应的路由和视图,只需要在这些类里面定义该操作处理函数即可,例如
{ {#if isExpanded}}{ { body}}{ { else}} { {/if}}
App.PostController = Ember.ObjectController.extend({ // initial value isExpanded: false, actions: { expand: function() { this.set('isExpanded', true); }, contract: function() { this.set('isExpanded', false); } } });
App.PostRoute = Ember.Route.extend({ actions: { expand: function() { this.controller.set('isExpanded', true); }, contract: function() { this.controller.set('isExpanded', false); } } });
App.PostsIndexView = Ember.View.extend({ actions: { select: function(post) { // do your business. } }});