简体   繁体   English

如何从余烬控制器触发路线动作

[英]How to trigger action on route from controller in ember

Considering this example: http://emberjs.jsbin.com/hecewi/1/edit?html,js,output 考虑以下示例: http : //emberjs.jsbin.com/hecewi/1/edit?html,js,output

The docs state that an action will be searched for on the controller first (which works in the example eg by pasting the actions hash into the IndexController ), then on the current route and then along its parent routes until it hits ApplicationRoute . docs声明,将首先在控制器上搜索动作(在示例中有效,例如,通过将actions哈希粘贴到IndexController ),然后在当前路径上沿其父路径搜索,直到到达ApplicationRoute为止。 I'd expect the testCamel action in the example to be triggered then, but instead there is an error about the route did not get handled. 我希望示例中的testCamel操作随后会被触发,但是关于路由的错误没有得到处理。 How to do it right? 怎么做对?

The code to trigger an action is indeed correct. 触发动作的代码确实是正确的。 It's just an unfortunate chosen example. 这只是一个不幸的例子。 Since your route will initialize the controller, the route itself is probably not completely initialized by the time the action is sent. 由于您的路由将初始化控制器,因此在发送操作时,路由本身可能尚未完全初始化。 If you, for example, schedule the action to be triggered in the following run loop, it works perfect: 例如,如果您安排要在以下运行循环中触发的动作,那么它会完美工作:

http://emberjs.jsbin.com/yaseva/1/edit http://emberjs.jsbin.com/yaseva/1/edit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM