通常、ビューからコントローラで宣言されたメソッドにアクセスするには、次を使用します。. この単純な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>