如何保持数据刷新页面? [英] How to keep the data on refresh a page?

查看:104
本文介绍了如何保持数据刷新页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从模型中获取了我的数据。在模型集成到页面之后,当我刷新页面时,数据将消失。



我想防止数据仍然刷新。在 EmberJs 中,正确的方法是什么?显示我正确的方法来阻止我的数据刷新?



我的型号代码:

 导出默认值Ember.Route.extend ({
model:function(params){
return this.store.peekRecord('card-list',params.id); // works
}
});

提前感谢



更新

 从ember导入Ember; 

导出默认值Ember.Route.extend({
model:function(params){

if(this.store.hasRecordForId('card-list' params.id)){
return Ember.RSVP.hash({
model:this.store.peekRecord('card-list',params.id)
})
}
//我正在尝试刷新,但是抛出错误为
//处理路由时出错:cs2i.balance.balanceEdit Ember数据请求GET / api / card-lists / 4196074912005007返回404
return Ember.RSVP.hash({
model:this.store.findRecord('card-list',params.id)
})
}
});


解决方案

您可以检查现有记录,除非提取。 / p>

 导出默认值Ember.Route.extend({
model:function(params){
if(this .store.hasRecordForId('card-list',params.id))
return this.store.peekRecord('card-list',params.id);
return this.store.findRecord(' card-list',params.id);
}
});


I am getting my data from the model. after the model integrated to page, when I refresh the page the data goes away.

I would like to prevent the data still on refresh. what is the correct way to do this in EmberJs any one show me the correct way to prevent my data from refresh?

my model code :

export default Ember.Route.extend({
  model: function(params) {
    return this.store.peekRecord('card-list', params.id ); //works
  }
});

Thanks in advance.

UPDATE

    import Ember from 'ember';

    export default Ember.Route.extend({
      model: function(params) {

        if(this.store.hasRecordForId('card-list', params.id)){
            return Ember.RSVP.hash({
                model: this.store.peekRecord('card-list', params.id ) 
            })
        }
    //I am trying for refresh. but throws error as
//Error while processing route: cs2i.balance.balanceEdit Ember Data Request GET /api/card-lists/4196074912005007 returned a 404
        return Ember.RSVP.hash({
            model: this.store.findRecord('card-list', params.id ) 
        })
      }
    });

解决方案

You can check for existing record unless fetching that.

export default Ember.Route.extend({
  model: function(params) {
    if(this.store.hasRecordForId('card-list', params.id))
      return this.store.peekRecord('card-list', params.id );
    return this.store.findRecord('card-list', params.id );
  }
});

这篇关于如何保持数据刷新页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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