是否可以从把手模板中调用另一个控制器方法?
<script type="text/x-handlebars" data-template-name="home">
<a {{action logout target="Application.loginController"}}>
logout
</a>
</script>
错误
Uncaught TypeError: Cannot read property 'send' of undefined ember.js:25757
(anonymous function) ember.js:25757
(anonymous function) ember.js:4509
Ember.handleErrors ember.js:411
invoke ember.js:4507
tryable ember.js:4692
Ember.tryFinally ember.js:1206
Ember.run ember.js:4696
ActionHelper.registeredActions.(anonymous function).handler ember.js:25756
(anonymous function) ember.js:14452
Ember.handleErrors ember.js:411
(anonymous function) ember.js:14444
b.event.dispatch jquery.js:3
v.handle jquery.js:3
环境
浏览器:Chrome版本26.0.1410.63
Ember:1.0.0-rc.3
把手:1.0.0-rc.3
Jquery:1.9.1
答案 0 :(得分:1)
您可以使用Ember的needs feature来完成此操作。
您指定控制器“需要”访问另一个控制器,然后Ember允许您在controllers.controllerName
访问它:
App.ApplicationController = Ember.Controller.extend({
applicationAction: function() {
console.log("action in application controller");
}
});
App.IndexController = Ember.ArrayController.extend({
needs: ['application'],
indexProperty: "index controller"
});
可以在模板中访问:
<a href='#' {{action applicationAction target="controllers.application"}}>
logout
</a>