DS#getAll
DS#getAll(resourceName[, ids])
Synchronously retrieve the items with the given IDs from data store of the type specified by resourceName.
If you omit the ids argument then all items of the specified resource type will be returned.
If you just want to get all items that are in the store of a particular resource type, this is the most efficient way to retrieve them (faster than DS#filter with no arguments).
You can call
DS#getAllmultiple ways
DS#getAll(resourceName[, ids])Resource#getAll([ids])- Where Resource was created byDS#defineResource
| Argument | Type | Description |
|---|---|---|
resourceName | string | The name of the resource to use. Unnecessary if using the resource directly. |
ids | array (of strings) | Optional. Array of primary keys of items to retrieve. If you omit the ids argument then all items of the specified resource type will be returned. |
Examples
var store = new JSData.DS();
var User = store.defineResource('user');
var users = User.inject([
{ id: 1, name: 'John' },
{ id: 2, name: 'Sally' },
{ id: 3, name: 'Fred' }
]);
users = User.getAll([2, 3]); // [{id:2,name:'Sally'},{id:3,name:'Fred'}]
users.length; // 2
users = User.getAll(); // [{...},{...},{...}]
users.length; // 3
Live Demo
Need help?
Want more examples or have a question? Ask on the Slack channel or post on the mailing list then we'll get your question answered and probably update this wiki.
Updated less than a minute ago
