javascript - EmberJS 中的 transitionTo LoadingRoute?

标签 javascript ember.js

是否可以通过 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'));     
}

因为过渡是中间的,所以浏览器历史记录不受影响,didTransitionwillTransition 操作不会在路由上触发。 intermediateTransitionTopart 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/

相关文章:

javascript - 能否在 Visual Studio 2013 中将 javascript 作为动态语言运行?

ember.js - Ember - 组件名称需要破折号让人有些头疼

javascript - Ember.js 从动态路由过滤数据

javascript - Ember.js 数据冲突解决/冲突失败

javascript - 在 React 中,componentDidMount 何时会为不直接呈现标记的组件触发?

javascript - 如何等待异步请求完成

javascript - derby.js vs capsule/thoonk?

c# - 将值从代码隐藏传递到 JavaScript 函数

javascript - Ember : No model was found for 'user' and Duplicate POSTs created when executing the save promise

ruby-on-rails - 有谁知道为什么 ember-data beta 6 会序列化像这样的日期属性 "1392258472591"