EmberJS - didInsertElement for previously displayed view

冷暖自知 提交于 2020-01-05 08:15:15

问题


I have a flow with multiple pages and when I use 'transitionTo' to go back to a route/view that has already been displayed, it's 'didInsertElement' method is not called. (it was fired the first time the view was displayed, though)

Is there an event that my view can hook into that will be called every time it is displayed?

My routes look something like this

App.Router.map(function() {
    this.resource("parent", { path: "/parent" }, function() {
        this.resource("child", { path: "/child" });
    });
});

So when I'm in the child view and call:

this.transitionTo('parent')

The parent view does not fire 'didInsertElement'.


回答1:


I found that I can use setupController in the routes to let me know each time the route is rendered. I know it's not the best solution, but so far, it is the most reliable.




回答2:


The parent is already rendered, as the child is rendered inside of the outlet in the parent. What are you trying to do when you transition back to the parent view? There might be a better way to do what you want




回答3:


If your routes are nested your templates should be too. So I would expect your template to look something like this:

<script type="text/x-handlebars" data-template-name="parent">
  <!-- Your parent View stuff -->

  {{outlet}} <!-- This is where your child gets rendered
</script>

So your parent view stuff is already inserted and stays inserted. It shouldn't be going anywhere when you transition into / out of the parent.

What exactly are you trying to do that you need the didInsertElement after transitioning back to the parent. The didInsertElement hook is really for lower level dom manipulation, like setting up jQuery plugins. If your trying to do more application logic stuff it probably belongs somewhere else.



来源:https://stackoverflow.com/questions/16929672/emberjs-didinsertelement-for-previously-displayed-view

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!