是否可以通过 Controller Action 触发加载路径?
例如:
App.PostsController = Ember.ArrayController.extend(
actions:
new:
# transitionTo loading
$.post(...).then (response) ->
# deactivate loading
)
我想避免为每个 Controller 添加自定义“加载”属性,而只使用内置的 LoadingRoute。
最佳答案
我在应用程序路由上创建了以下两个操作
startLoading: function () {
this.set('returnRoute', this.controller.get('currentRouteName'));
this.intermediateTransitionTo('loading');
},
endLoading: function () {
this.intermediateTransitionTo(this.get('returnRoute'));
}
因为过渡是中间的,所以浏览器历史记录不受影响,didTransition
、willTransition
操作不会在路由上触发。 intermediateTransitionTo
是 part of the public API ,因此使用起来应该是安全的。
然后我将这些 Action 用作
someAction: function() {
var that = this;
this.send('startLoading');
longTask().then(function() {
that.send('endLoading');
});
}
关于javascript - EmberJS 中的 transitionTo LoadingRoute?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19549751/