关闭动作应在控制器上定义 [英] Closure actions should be defined on controller

查看:125
本文介绍了关闭动作应在控制器上定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ember 1.13.10



我想尝试关闭操作,所以我定义了一个路由:

  import Ember from'ember'; 

export default Ember.Route.extend({
actions:{
doSave(){...}
}
}

和范本:

  {{my-component onSave =(action'doSave')}} 

但是我得到错误消息:在(生成test.index控制器)中找不到名为doSave的操作。



但是它在路由上定义。考虑到控制器在Ember中被弃用的事实,我预计应该在路由而不是控制器上定义操作。
在控制器上定义闭包操作的具体原因是什么?

解决方案

控制器不是路由,一旦可路由的组件将它们替换控制器。



在你的情况下,如果你想泡泡的行动,你必须从控制器发送它。 / p>

Ember 1.13.10

I wanted to try out the closure actions, so I defined the a route:

import Ember from 'ember';

export default Ember.Route.extend({
  actions: {
    doSave() { ... }
  }
});

and the template:

{{my-component onSave=(action 'doSave')}}

But I get the error message: An action named 'doSave' was not found in (generated test.index controller).

However it is defined on the route. Given the fact that Controllers are kind of deprecated in Ember I would expect that the action should be defined on the route instead of the controller. Is there a specific reason why the closure actions should be defined on the controller?

解决方案

Closure actions communicate with the controller not the route, once routable components land they will replace controllers.

In your case if you wish to bubble the action you will have to send it from the controller.

这篇关于关闭动作应在控制器上定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆