Reputation: 15293
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 )
})
}
});
Upvotes: 0
Views: 779
Reputation: 9043
You must be 'peeking' the record of a parent route that fetches the record with query or findRecord or findAll etc... so - there could be many reasons your data is 'goes away'...
If you are not in a child route of something... that peekRecord has nothing to 'peek'... so, you'd have to check for the record... or get the modelFor('model-name') - from a parent route... - so, you'll need to provide more information about the context of your code.
// imports whatevers...
model(parameters) {
return this.store.findRecord('thing', parameter.id);
}
or....
model() {
var x = this.modelFor('parentModel');
// do something with x... query... find etc...
}
Upvotes: 1
Reputation: 9406
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 );
}
});
Upvotes: 1