获取加载路线的状态

时间:2014-10-24 05:20:58

标签: ember.js ember-data ember-router

我的路线中有以下查询参数:

queryParams:
  search:
    refreshModel: true

当我更改search param时,所有内容都会按预期更改并重新加载模型。

问题是:如何检查路线是否仍在刷新?

PS:model.isLoadedtrue,因为页面首次加载。

UPD:我想要实现的目标:我有ObjectsController,里面有搜索和表格。当用户提交他的查询时,我想隐藏表并显示一个微调器。

3 个答案:

答案 0 :(得分:4)

帮助我的解决方案。

Ember.Route有两个有用的事件loadingdidTransition

actions:
   loading: ->
     @controller.set('loading', true) if @controller
   didTransition: ->
     @controller.set('loading', false) if @controller

然后在tempalate:

..search form..
{{#if loading}}
   show spinner
{{else}}
   ..render collection..
{{/if}}

答案 1 :(得分:0)

只要查询参数移回路径的模型函数时,路径应该回到加载状态,请参阅我的示例bin

http://jsbin.com/felice

答案 2 :(得分:0)

您的路由器是:

App.Router.map(function(){
  this.resource('objects', function(){      
    this.route('new');                      
  });  
});

如果您的ObjectsIndexRoute返回不立即解析的承诺,Ember将尝试在层次结构中找到加载路径

-objects.loading
-loading

'对象/加载'模板将呈现在'对象的子模板(例如,对象/索引)的区域上。模板渲染。

请查看http://emberjs.com/guides/routing/loading-and-error-substates/了解更多详情。

工作箱:http://jsbin.com/bomupe/1

我将搜索表单放在对象模板中,并生成对象/索引模板。对象/加载模板在加载时替换对象/索引。

更新:

JSBin:http://jsbin.com/wenuy/1。要交替加载'使用布尔属性旋转器和搜索结果。

相关问题