.. _quickstart/data/usingdatastores/fetchsingle: Selecting single items ====================== .. contents:: :depth: 3 A common desire is to retrieve a single item of data and display it in some fashion. Dojo.data provides an API definition that can be implemented by DataStores to make this a simple operation. The API is called the Identity API and the definition can be found :ref:`here `. For this example, we'll assume the following simple data source: .. code-block :: javascript { identifier: 'name', items: [ { name: 'Adobo', aisle: 'Mexican', price: 3.01 }, { name: 'Balsamic vinegar', aisle: 'Condiments', price: 4.01 }, { name: 'Basil', aisle: 'Spices', price: 3.59 }, { name: 'Bay leaf', aisle: 'Spices', price: 2.01 }, { name: 'Beef Bouillon Granules', aisle: 'Soup', price: 5.01 }, { name: 'Vinegar', aisle: 'Condiments', price: 1.99 }, { name: 'White cooking wine', aisle: 'Condiments', price: 2.01 }, { name: 'Worcestershire Sauce', aisle: 'Condiments', price: 3.99 }, { name: 'pepper', aisle: 'Spices', price: 1.01 } ]} ======== Examples ======== The following example will make use of APIs defined by both :ref:`Read ` and :ref:`Identity `. In specific, they use: **Identity** fetchItemByIdentity() Fetches an item by its key value. Because the identity value of each item is unique, you are guaranteed at most one answer back. **Read** getValue() Takes an item and an attribute and returns the associated value Fetch by Identity ----------------- This example shows how to fetch items by their identity programmatically. .. cv-compound :: .. cv :: javascript .. cv :: html Pick a grocery item:


AISLE:
PRICE:
**Note:** In the example, the fetchItemByIdentity makes use of a callback to pass the fetched item to. This is because by definition, dojo.data is an asynchronous API for querying of data values. This is because many Data Stores will need to go back to a server to actually look up the data and some Ajax I/O methods do not readily allow for a synchronous call. For example, script source IO cannot be done synchronously, nor can iFrame IO. They must have callbacks to operate.