使用refreshModel加载模型挂钩 [英] Model hook loading with refreshModel

查看:79
本文介绍了使用refreshModel加载模型挂钩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的路线当前如下:

 导出默认Ember。 Route.extend({
queryParams:{
dateFrom:{refreshModel:true},
dateTo:{refreshModel:true}
},

模型(参数){
返回this.store.findRecord('foo',params.id,{
adapterOptions:{
过滤器:{
dateFrom:params.dateFrom,
dateTo:params.dateTo,
}
}
});
},
});

在路径上更改查询参数时,将再次触发模型挂钩。有没有办法可以判断模型挂钩是否处于加载状态?我已经在模板中尝试了 model.isLoading ,但是当触发 refreshModel 时,该值似乎没有更新。 / p>

我不想使用加载子状态,因为我需要一个可以传递给组件的属性。

解决方案

我不确定这种方法,但是仍然可以在路线内尝试,

  actions:{
loading(transition,originRoute){
//如果要设置控制器属性,则this.controller.set('isLoading',true);将执行
this.set('isLoading',true);
transition.promise.finally(()=> {
this.set(’isLoading’,false);
});
返回true;
}
}


My Route currently looks like:

export default Ember.Route.extend({
    queryParams: {
        dateFrom: { refreshModel: true },
        dateTo: { refreshModel: true }
    },

    model(params) {
        return this.store.findRecord('foo', params.id, {
            adapterOptions: {
                filter: {
                    dateFrom: params.dateFrom,
                    dateTo: params.dateTo,
                }
            }
        });
    },
});

When the query param is changed on the route, the model hook is fired again. Is there a way I can tell if the model hook is in a loading state? I have tried model.isLoading in my template, but this doesn't seem to update when refreshModel is triggered.

I don't want to use loading substates, as I need a property I can pass into components.

解决方案

I am not sure about this approach, but still, you can try it inside the route,

actions: {
        loading(transition, originRoute) {
            //if you want to set controller property, this.controller.set('isLoading',true); will do
            this.set('isLoading',true);          
            transition.promise.finally(() => {
               this.set('isLoading',false);                   
            });
            return true;
        }
    }

这篇关于使用refreshModel加载模型挂钩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆