简体   繁体   中英

How to trigger action on route from controller in ember

Considering this example: 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 . 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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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