是' store '.找到"函数"不同于"存储".在Ember JS上的find



在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.

最新更新