dojox/data/ServiceStore (version 1.10)

Summary

note that dojox.rpc.Service is not required, you can create your own services A ServiceStore is a readonly data store that provides a data.data interface to an RPC service.

var myServices = new dojox.rpc.Service(dojo.moduleUrl("dojox.rpc.tests.resources", "test.smd"));
var serviceStore = new dojox.data.ServiceStore({service:myServices.ServiceStore});

The ServiceStore also supports lazy loading. References can be made to objects that have not been loaded. For example if a service returned:

{"name":"Example","lazyLoadedObject":{"$ref":"obj2"}}

And this object has accessed using the dojo.data API:

var obj = serviceStore.getValue(myObject,"lazyLoadedObject");

The object would automatically be requested from the server (with an object id of "obj2").

Usage

var foo = new ServiceStore(options);
dojox/data/ServiceStore
<

ServiceStore can do client side caching and result set updating if dojox.data.ClientFilter is loaded. Do this add:

dojo.require("dojox.data.ClientFilter")

prior to loading the ServiceStore (ClientFilter must be loaded before ServiceStore).

To utilize client side filtering with a subclass, you can break queries into client side and server side components by putting client side actions in clientFilter property in fetch calls. For example you could override fetch:

fetch: function(args){
    // do the sorting and paging on the client side
    args.clientFilter = {start:args.start, count: args.count, sort: args.sort};
    // args.query will be passed to the service object for the server side handling
    return this.inherited(arguments);
}

When extending this class, if you would like to create lazy objects, you can follow

the example from dojox.data.tests.stores.ServiceStore:

var lazyItem = {
    _loadObject: function(callback){
        this.name="loaded";
        delete this._loadObject;
        callback(this);
    }
};
>ServiceStore can do client side caching and result set updating if dojox.data.ClientFilter is loaded. Do this add:

dojo.require("dojox.data.ClientFilter")

prior to loading the ServiceStore (ClientFilter must be loaded before ServiceStore).

To utilize client side filtering with a subclass, you can break queries into client side and server side components by putting client side actions in clientFilter property in fetch calls. For example you could override fetch:

fetch: function(args){
    // do the sorting and paging on the client side
    args.clientFilter = {start:args.start, count: args.count, sort: args.sort};
    // args.query will be passed to the service object for the server side handling
    return this.inherited(arguments);
}

When extending this class, if you would like to create lazy objects, you can follow

the example from dojox.data.tests.stores.ServiceStore:

var lazyItem = {
    _loadObject: function(callback){
        this.name="loaded";
        delete this._loadObject;
        callback(this);
    }
};
>
Parameter Type Description
options undefined

Keyword arguments

The schema parameter

This is a schema object for this store. This should be JSON Schema format.

The service parameter

This is the service object that is used to retrieve lazy data and save results The function should be directly callable with a single parameter of an object id to be loaded

The idAttribute parameter

Defaults to 'id'. The name of the attribute that holds an objects id. This can be a preexisting id provided by the server. If an ID isn't already provided when an object is fetched or added to the store, the autoIdentity system will generate an id for it and add it to the index.

The estimateCountFactor parameter

This parameter is used by the ServiceStore to estimate the total count. When paging is indicated in a fetch and the response includes the full number of items requested by the fetch's count parameter, then the total count will be estimated to be estimateCountFactor multiplied by the provided count. If this is 1, then it is assumed that the server does not support paging, and the response is the full set of items, where the total count is equal to the number of items returned. If the server does support paging, an estimateCountFactor of 2 is a good value for estimating the total count It is also possible to override _processResults if the server can provide an exact total count.

The syncMode parameter

Setting this to true will set the store to using synchronous calls by default. Sync calls return their data immediately from the calling function, so callbacks are unnecessary. This will only work with a synchronous capable service.

See the dojox/data/ServiceStore reference documentation for more information.

Property Summary

  • _currentId
  • estimateCountFactorThis parameter is used by the ServiceStore to estimate the total count.
  • idAttributeDefaults to &#39;id&#39;.
  • labelAttribute
  • loadLazyValues
  • schemaThis is a schema object for this store.
  • serviceThis is the service object that is used to retrieve lazy data and save results The function should be directly callable with a single parameter of an object id to be loaded
  • syncModeSetting this to true will set the store to using synchronous calls by default.

Method Summary

  • _doQuery(args)
  • _processResults(results,deferred)
  • close(request)
  • containsValue(item,attribute,value) Checks to see if 'item' has 'value' at 'attribute'
  • fetch(args) See dojo/data/api/Read.fetch
  • fetchItemByIdentity(args) fetch an item by its identity, by looking in our index of what we have loaded
  • getAttributes(item) Gets the available attributes of an item's 'property' and returns it as an array.
  • getFeatures() return the store feature set
  • getIdentity(item)
  • getIdentityAttributes(item) returns the attributes which are used to make up the identity of an item.
  • getLabel(item) returns the label for an item.
  • getLabelAttributes(item) returns an array of attributes that are used to create the label of an item
  • getSchema() Returns a reference to the JSON Schema
  • getValue(item,property,defaultValue) Gets the value of an item's 'property'
  • getValues(item,property) Gets the value of an item's 'property' and returns it.
  • hasAttribute(item,attribute) Checks to see if item has attribute
  • isItem(item) Checks to see if the argument is an item
  • isItemLoaded(item) Checks to see if the item is loaded.
  • loadItem(args) Loads an item and calls the callback handler.

Properties

_currentId
estimateCountFactor

This parameter is used by the ServiceStore to estimate the total count. When paging is indicated in a fetch and the response includes the full number of items requested by the fetch's count parameter, then the total count will be estimated to be estimateCountFactor multiplied by the provided count. If this is 1, then it is assumed that the server does not support paging, and the response is the full set of items, where the total count is equal to the numer of items returned. If the server does support paging, an estimateCountFactor of 2 is a good value for estimating the total count It is also possible to override _processResults if the server can provide an exact total count.

idAttribute

Defaults to 'id'. The name of the attribute that holds an objects id. This can be a preexisting id provided by the server. If an ID isn't already provided when an object is fetched or added to the store, the autoIdentity system will generate an id for it and add it to the index.

labelAttribute
loadLazyValues
schema

This is a schema object for this store. This should be JSON Schema format.

service

This is the service object that is used to retrieve lazy data and save results The function should be directly callable with a single parameter of an object id to be loaded

syncMode

Setting this to true will set the store to using synchronous calls by default. Sync calls return their data immediately from the calling function, so callbacks are unnecessary. This will only work with a synchronous capable service.

Methods

_doQuery(args)
Parameter Type Description
args undefined
Returns:undefined
_processResults(results,deferred)
Parameter Type Description
results undefined
deferred undefined
Returns:object
close(request)
Parameter Type Description
request undefined
Returns:undefined
containsValue(item,attribute,value)

Checks to see if 'item' has 'value' at 'attribute'

Parameter Type Description
item Object
attribute String
value Anything
Returns:boolean
fetch(args)

See dojo/data/api/Read.fetch

Parameter Type Description
args undefined

The queryOptions.cache parameter

If true, indicates that the query result should be cached for future use. This is only available if dojox.data.ClientFilter has been loaded before the ServiceStore

The syncMode parameter

Indicates that the call should be fetch synchronously if possible (this is not always possible)

The clientFetch parameter

This is a fetch keyword argument for explicitly doing client side filtering, querying, and paging

Returns:string
fetchItemByIdentity(args)

fetch an item by its identity, by looking in our index of what we have loaded

Parameter Type Description
args undefined
Returns:undefined
getAttributes(item)

Gets the available attributes of an item's 'property' and returns it as an array.

Parameter Type Description
item Object
Returns:Array
getFeatures()

return the store feature set

Returns:object
getIdentity(item)
Parameter Type Description
item undefined
Returns:undefined
getIdentityAttributes(item)

returns the attributes which are used to make up the identity of an item. Basically returns this.idAttribute

Parameter Type Description
item undefined
Returns:Array
getLabel(item)

returns the label for an item. Just gets the "label" attribute.

Parameter Type Description
item undefined
Returns:undefined
getLabelAttributes(item)

returns an array of attributes that are used to create the label of an item

Parameter Type Description
item undefined
Returns:Array
getSchema()

Returns a reference to the JSON Schema

Returns:Object | undefined
getValue(item,property,defaultValue)

Gets the value of an item's 'property'

Parameter Type Description
item Object

The item to get the value from

property String

property to look up value for

defaultValue value
Optional

the default value

Returns:return the plain value since it was found;
getValues(item,property)

Gets the value of an item's 'property' and returns it. If this value is an array it is just returned, if not, the value is added to an array and that is returned.

Parameter Type Description
item Object
property String

property to look up value for

Returns:Array
hasAttribute(item,attribute)

Checks to see if item has attribute

Parameter Type Description
item Object
attribute String
Returns:boolean
isItem(item)

Checks to see if the argument is an item

Parameter Type Description
item Object
Returns:boolean
isItemLoaded(item)

Checks to see if the item is loaded.

Parameter Type Description
item object
Returns:undefined
loadItem(args)

Loads an item and calls the callback handler. Note, that this will call the callback handler even if the item is loaded. Consequently, you can use loadItem to ensure that an item is loaded is situations when the item may or may not be loaded yet. If you access a value directly through property access, you can use this to load a lazy value as well (doesn't need to be an item).

Parameter Type Description
args undefined
Returns:undefined

Examples

Example 1

store.loadItem({
    item: item, // this item may or may not be loaded
    onItem: function(item){
        // do something with the item
    }
});
Error in the documentation? Can’t find what you are looking for? Let us know!