在Ember JS服务"store"上有两个类似的函数。在本例中,它们的工作方式相似。
find
函数
@service store;
async model(params) {
return this.store.find('rental', params.rental_id);
}
findRecord
函数
@service store;
async model(params) {
return this.store.findRecord('rental', params.rental_id);
}
它们不同吗?或者只是一个别名?
store.find
为private,不推荐使用。store.findRecord
是通过id查找特定记录的正确方法。
你可以在这里看到更多的细节。
store.find
// The default `model` hook in Route calls `find(modelName, id)`,
// that's why we have to keep this method around even though `findRecord` is
// the public way to get a record by modelName and id.