gpt4 book ai didi

ember.js - 观察路线变化以适用于onload

转载 作者:行者123 更新时间:2023-12-04 13:33:05 24 4
gpt4 key购买 nike

我正在尝试观察路线更改,以在渲染后应用一些常见操作。这个想法是要具有类似于onload的功能,但是由于我们使用的是单页应用程序,因此需要在每次路线更改时触发该功能。 (可以限制为新 View )

我发现了如何观察currentPath的变化:

App.ApplicationController = Ember.Controller.extend({
currentPathDidChange: function() {
prettyPrint()
}.observes('currentPath');
});

尽管这在某些情况下效果很好,但它会在路线更改时触发,但仍要及早应用内容更改,因为它似乎在呈现内容之前追加了。

对实现该目标的最佳实践有什么想法?

最佳答案

您是否尝试过使用 Ember.run.schedule 推迟代码?例如,

App.ApplicationController = Ember.Controller.extend({
currentPathDidChange: function() {
Ember.run.schedule('afterRender', this, function() {
prettyPrint();
});
}.observes('currentPath')
});

关于ember.js - 观察路线变化以适用于onload,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16023103/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com