this.store.find('type')
总是会调用服务器进行记录。如果您只想对服务器进行一次调用,请在ApplicationRoute
然后而不是使用find
使用all
过滤多次命中的路由内部。
Pd.ApplicationRoute = Em.Route.extend({
model: function(params){
return Em.RSVP.hash({
product: this.store.find('product'),
somethingElse: otherPromise
})
}
});
Pd.ProductRoute = Em.Route.extend({
model: function(params){
return this.store.all('product');
}
});
如果您只是想为商店准备好您的产品,您甚至不需要退货,或者在应用程序路径中使用它
Pd.ApplicationRoute = Em.Route.extend({
model: function(params){
this.store.find('product');
return {foo:'bar'}; // or return nothing, it doesn't matter
}
});
延迟加载模型
App.ProductRoute = Ember.Route.extend({
hasPreLoaded: false,
model: function() {
if(this.get('hasPreLoaded')){
return this.store.all('product');
} else {
this.toggleProperty('hasPreLoaded');
return this.store.find('product');
}
}
});
Example
http://emberjs.jsbin.com/OxIDiVU/482/edit
您不在适配器上定义主键,它在序列化器上定义
Pd.ProductSerializer = DS.RESTSerializer.extend({
primaryKey: 'nid'
});
缓存不再存在于那里,它存在于this.store.typeMapFor(Pd.Product)
or this.store.typeMaps
.
在 ember data 1.0 发布之前,该网站仍然引用旧版本的 ember data,我假设您使用的是 1.0 beta 版本。该文档是最新的https://github.com/emberjs/data/blob/master/TRANSITION.md