js-data

Respect Your Data

Give your data the treatment it deserves with a framework-agnostic, datastore-agnostic JavaScript ORM built for ease of use and peace of mind. Works in Node.js and in the Browser.

Get Started

DS#get

DS#get(resourceName, id)

Synchronously return the item with the given id from the store.

Returns undefined if the item is not in the store.

👍

You can call DS#get multiple ways

  • DS#get(resourceName, id)
  • Resource#get(id) - Where Resource was created by DS#defineResource

Argument

Type

Description

resourceName

string

The name of the resource to use. Unnecessary if using the resource directly.

id

string or number

The primary key of the item to retrieve.

Examples
var store = new JSData.DS();
var User = store.defineResource('user');

var user = User.inject({ id: 1, name: 'John' });

User.get(1); // { id: 1, name: 'John' }
user === User.get(1); // true

// item is not in the store
User.get(2); // undefined
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

DS#get


DS#get(resourceName, id)

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.