Ember JS上的“store.find”函数与“store.findRecord”函数不同吗?

zaq34kh6  于 2023-01-08  发布在  其他
关注(0)|答案(1)|浏览(186)

在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);
  }

他们是不同的吗?还是只是化名?

ezykj2lf

ezykj2lf1#

store.find是私有的,已弃用。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.

相关问题