Retrieving
Use store.getResources()
to access resource data from the store.
Filtering by ID
Sometimes, you may have the specific IDs that you wish to pull from the store. In these situations, you can pass an array of IDs to getResources
.
Filtering with an object
If you want a set of resources with specific attributes, meta, or computed attributes, you can pass an object as the second argument. Any resource that matches the object will be returned.
In the following example, we return every book that was published in 1970.
Filtering with a function
You can pass a function as a filter as well. The filter will be called with two arguments:
resource
: a resource objectresources
: all of the resources of the same resource type
Return true
from the function to include the resource
in the results.
In this example, we return every book that doesn't have a publish year:
Options
getResources
accepts a third argument, options
. Currently, only option is supported: byId
.
Pass true
, and you will receive an object back instead of an array, where each key of the object is a resource ID.
Last updated