我有这条路线检索 2 个模型:
App.PanelRoute = Ember.Route.extend({
model: function(){
var topologymin = this.store.find('topologymin');
var metricmap = this.store.find('metricmap', { param1: 'something'})
return Ember.RSVP.hash({
topologymin: topologymin,
metricmap: metricmap
});
});
这会进行 2 次调用:
http://localhost/topologymins
http://localhost/metricmaps?param1=something
如果我转到另一条路线并再次到达这条路线,它会再次使用参数而不是另一条进行调用:
http://localhost/metricmaps?param1=something
但是,由于它是检索相同记录的相同调用,我希望它们像在其他调用中一样被缓存。
它如何知道何时调用服务器以及何时不需要?有可能吗?
我的模型:
App.Topologymin = DS.Model.extend({
siteGroup: DS.attr('string'),
sites: DS.hasMany('site')
});
App.Metricmap = DS.Model.extend({
profile: DS.attr('string'),
link: DS.attr('string'),
services: DS.attr()
});
最佳答案
当您基于参数发出请求时,Ember Data 不知道这些参数如何必然转化为模型(也不知道您拥有具有某种关系 param1 的所有记录)。您可以自己缓存它,但您仍然需要某种方式从商店中的其他记录中了解这些记录。
App.PanelRoute = Ember.Route.extend({
model: function(){
var met = this.get('fetchedBeforePromise'),
topologymin = this.store.find('topologymin'),
metricmap = met || this.store.find('metricmap', { param1: 'something'});
this.set('fetchedBeforePromise', metricmap);
return Ember.RSVP.hash({
topologymin: topologymin,
metricmap: metricmap
});
});
关于ember.js - 在调用中使用查询参数时缓存记录? Ember 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23803388/