通常,我们可以使用以下命令从视图访问控制器中声明的方法:this.get('controller').send('method'); . 在这个简单的jsfiddle中,失败并显示:Uncaught TypeError: Cannot read property 'send' of undefined。
这是jsfiddle中的完整代码。
App = Ember.Application.create();
App.YesController = Ember.ArrayController.extend({
cow: function(){
console.log('say mooooo') ;
}
});
App.YesView = Ember.View.extend({
templateName: 'yes',
um: function(){
this.get('controller').send('cow');
}
});
整体观点:
<script type='text/x-handlebars' data-template-name='application'>
{{render yes}}
{{outlet}}
</script>
<script type='text/x-handlebars' data-template-name='yes'>
<h1> Can't use send to call controller method from view</h1>
<button {{action 'um' target='view.content'}}> can't call controller from view</button>
<button {{action 'cow'}}> controller action works</button>
</script>