home / dojo / data / api / Read

dojo.data Read API

Deprecated, dojo/store will eventually replace the dojo/data API.

The most fundamental API of dojo.data is the Read API. All stores will implement this API because all stores need the ability to retrieve and process data items. The Read API is designed to be extremely flexible in how items are handled. The Read API provides the ability to:

Examples

The following examples, guidelines, and complete API documentation provide further information on the Read API:

Listing the APIs supported by a datastore

var store = new some.Datastore();
var features = store.getFeatures();
for(var i in features){
  console.log("Store supports feature: " + i);
}

Testing if an object is a store item

var store = new some.Datastore();
if(store.isItem(someObject)){
  console.log("Object was an item.");
}else{
  console.log("Object was NOT an item.");
}

Listing the attributes of an item

var store = new some.Datastore();
... // Assume that someItem is an item we got from a load.
var attributes = store.getAttributes(someItem);
for(var i = 0; i < attributes.length; i++){
  console.log("Item has attribute: " + attributes[i]);
}

Testing an item for an attribute

var store = new some.Datastore();
...
// Assume that someItem is an item we got from a load.
if(store.hasAttribute(someItem, "foo")){
  console.log("item has attribute foo.");
}else{
  console.log("item DOES NOT have attribute foo.");
}

Getting the label of an item

var store = new some.Datastore();
...
// Assume that someItem is an item we got from a load.
var label = store.getLabel(someItem);
console.log("item has label: " + label);

Fetching all the items from the store

var store = new some.Datastore();
var gotItems = function(items, request){
  console.log("Number of items located: " + items.length);
};
store.fetch({onComplete: gotItems});

Further examples

Further examples of the API usage are covered in the Using Datastores section. Refer to it for examples on paging, sorting, selecting, and so forth.