本文介绍了离开路线时的Ember清理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在离开路线时进行一些清理,例如停止计时器。为此,我需要一个在离开路线时触发的事件,我需要访问该事件的控制器实例。



有一个退出事件,但它没有任何参数,而 this.get('controller')里面也不行 - 返回



退出事件中是否有正确的方法来获取控制器实例,或者也许是我不知道的另一个事件?



我设置有一个我想要的例子。

解决方案

你可以实现这个通过调用 this.controllerFor('home')。您可以尝试。



这有点恼人,所以最近,您可以直接使用 this.controller ,您可以看到。


I want to make some cleanup when i leave route, like stopping timers. For that i need an event that triggers when leaving the route, and i need access to instance of controller inside of that event.

There is an exit event, but it doesn't get any arguments, and this.get('controller') inside it doesn't work too - returns undefined.

Is there a proper way for obtaining controller instance in the exit event, or, maybe, another event that i don't know of?

I setup this fiddle with an example of what i want..

解决方案

You can achieve this by calling this.controllerFor('home'). You can try it in this JSFiddle.

This is a little bit annoying, so a pull request has been merged recently that allows you to directly use this.controller, as you can see in this JSFiddle.

这篇关于离开路线时的Ember清理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 11:27