我已经得到了这条路线检索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
});
});