dojox/data/AndOrReadStore (version 1.10)

dojo/data/ItemFileReadStore

Summary

AndOrReadStore uses ItemFileReadStore as a base, modifying only the query (_fetchItems) section. Supports queries of the form: query:"id:1 OR dept:'Sales Department' || (id:2 && NOT dept:S*)" Includes legacy/widget support via:

query:{complexQuery:"id:1* OR dept:'Sales Department' || (id:2* && NOT dept:S*)"}

The ItemFileReadStore implements the dojo/data/api/Read API and reads

data from JSON files that have contents in this format --

{ items: [
    { name:'Kermit', color:'green', age:12, friends:['Gonzo', {_reference:{name:'Fozzie Bear'}}]},
    { name:'Fozzie Bear', wears:['hat', 'tie']},
    { name:'Miss Piggy', pets:'Foo-Foo'}
]}

Note that it can also contain an 'identifier' property that specified which attribute on the items

in the array of items that acts as the unique identifier for that item.

Usage

var foo = new AndOrReadStore(keywordParameters);
dojo/data/ItemFileReadStore
Parameter Type Description
keywordParameters Object

{url: String} {data: jsonObject} {typeMap: object} The structure of the typeMap object is as follows:

{
    type0: function || object,
    type1: function || object,
    ...
    typeN: function || object
}

Where if it is a function, it is assumed to be an object constructor that takes the

value of _value as the initialization parameters. If it is an object, then it is assumed to be an object of general form:

{
    type: function, //constructor.
    deserialize:    function(value) //The function that parses the value and constructs the object defined by type appropriately.
}

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

Property Summary

  • _ccUrl
  • clearOnCloseParameter to allow users to specify if a close call should force a reload or not.
  • data
  • failOkParameter for specifying that it is OK for the xhrGet call to fail silently.
  • hierarchicalParameter to indicate to process data from the url as hierarchical (data items can contain other data items in js form).
  • typeMap
  • url
  • urlPreventCacheParameter to allow specifying if preventCache should be passed to the xhrGet call or not when loading data from a url.

Method Summary

  • _addReferenceToMap(refItem,parentItem,attribute) Method to add an reference map entry for an item and attribute.
  • _assertIsAttribute(attribute) This function tests whether the item passed in is indeed a valid 'attribute' like type for the store.
  • _assertIsItem(item) This function tests whether the item passed in is indeed an item in the store.
  • _containsValue(item,attribute,value,regexp) Internal function for looking at the values contained by the item.
  • _fetchItems(keywordArgs,findCallback,errorCallback) See dojo/data/util.simpleFetch.fetch()
  • _forceLoad() Internal function to force a load of the store if it hasn't occurred yet.
  • _getItemByIdentity(identity) Internal function to look an item up by its identity map.
  • _getItemsArray(queryOptions) Internal function to determine which list of items to search over.
  • _getItemsFromLoadedData(dataObject) Function to parse the loaded data into item format and build the internal items array.
  • _handleQueuedFetches() Internal function to execute delayed request in the store.
  • close(request) See dojo/data/api/Read.close()
  • containsValue(item,attribute,value) See dojo/data/api/Read.containsValue()
  • emit(type,event)
  • errorHandler(errorData,requestObject) The error handler when there is an error fetching items.
  • fetch(request) The simpleFetch mixin is designed to serve as a set of function(s) that can be mixed into other datastore implementations to accelerate their development.
  • fetchHandler(items,requestObject) The handler when items are successfully fetched.
  • fetchItemByIdentity(keywordArgs) See dojo/data/api/Identity.fetchItemByIdentity()
  • filter(requestArgs,arrayOfItems,findCallback)
  • getAttributes(item) See dojo/data/api/Read.getAttributes()
  • getFeatures() See dojo/data/api/Read.getFeatures()
  • getIdentity(item) See dojo/data/api/Identity.getIdentity()
  • getIdentityAttributes(item) See dojo/data/api/Identity.getIdentityAttributes()
  • getLabel(item) See dojo/data/api/Read.getLabel()
  • getLabelAttributes(item) See dojo/data/api/Read.getLabelAttributes()
  • getValue(item,attribute,defaultValue) See dojo/data/api/Read.getValue()
  • getValues(item,attribute) See dojo/data/api/Read.getValues()
  • hasAttribute(item,attribute) See dojo/data/api/Read.hasAttribute()
  • isItem(something) See dojo/data/api/Read.isItem()
  • isItemLoaded(something) See dojo/data/api/Read.isItemLoaded()
  • loadItem(keywordArgs) See dojo/data/api/Read.loadItem()
  • on(type,listener)

Properties

_ccUrl
clearOnClose

Parameter to allow users to specify if a close call should force a reload or not. By default, it retains the old behavior of not clearing if close is called. But if set true, the store will be reset to default state. Note that by doing this, all item handles will become invalid and a new fetch must be issued.

data
failOk

Parameter for specifying that it is OK for the xhrGet call to fail silently.

hierarchical

Parameter to indicate to process data from the url as hierarchical (data items can contain other data items in js form). Default is true for backwards compatibility. False means only root items are processed as items, all child objects outside of type-mapped objects and those in specific reference format, are left straight JS data objects.

typeMap
url
urlPreventCache

Parameter to allow specifying if preventCache should be passed to the xhrGet call or not when loading data from a url. Note this does not mean the store calls the server on each fetch, only that the data load has preventCache set as an option. Added for tracker: #6072

Methods

_addReferenceToMap(refItem,parentItem,attribute)

Method to add an reference map entry for an item and attribute.

Method to add an reference map entry for an item and attribute.

Parameter Type Description
refItem item

The item that is referenced.

parentItem item

The item that holds the new reference to refItem.

attribute string

The attribute on parentItem that contains the new reference.

_assertIsAttribute(attribute)

This function tests whether the item passed in is indeed a valid 'attribute' like type for the store.

Parameter Type Description
attribute attribute-name-string

The attribute to test for being contained by the store.

_assertIsItem(item)

This function tests whether the item passed in is indeed an item in the store.

Parameter Type Description
item dojo/data/api/Item

The item to test for being contained by the store.

_containsValue(item,attribute,value,regexp)

Internal function for looking at the values contained by the item.

Internal function for looking at the values contained by the item. This function allows for denoting if the comparison should be case sensitive for strings or not (for handling filtering cases where string case should not matter)

Parameter Type Description
item dojo/data/api/Item

The data item to examine for attribute values.

attribute attribute-name-string

The attribute to inspect.

value anything

The value to match.

regexp String | RegExp
Optional

Optional string or regular expression generated off value if value was of string type to handle wildcarding. If present and attribute values are string, then it can be used for comparison instead of 'value' If RegExp is a string, it is treated as an comparison statement and eval for number comparisons

Returns:undefined
_fetchItems(keywordArgs,findCallback,errorCallback)

See dojo/data/util.simpleFetch.fetch()

Parameter Type Description
keywordArgs Object
findCallback Function
errorCallback Function
_forceLoad()

Internal function to force a load of the store if it hasn't occurred yet. This is required for specific functions to work properly.

_getItemByIdentity(identity)

Internal function to look an item up by its identity map.

Parameter Type Description
identity Object
Returns:null
_getItemsArray(queryOptions)

Internal function to determine which list of items to search over.

Parameter Type Description
queryOptions object
Optional
Returns:undefined
_getItemsFromLoadedData(dataObject)

Function to parse the loaded data into item format and build the internal items array.

Function to parse the loaded data into item format and build the internal items array.

Parameter Type Description
dataObject Object

The JS data object containing the raw data to convery into item format.

Returns:Array

Array of items in store item format.

_handleQueuedFetches()

Internal function to execute delayed request in the store.

close(request)

See dojo/data/api/Read.close()

Parameter Type Description
request dojo/data/api/Request | Object
Optional
containsValue(item,attribute,value)

See dojo/data/api/Read.containsValue()

Parameter Type Description
item dojo/data/api/Item
attribute attribute-name-string
value anything
Returns:undefined
emit(type,event)
Defined by dojo/Evented
Parameter Type Description
type undefined
event undefined
Returns:undefined
errorHandler(errorData,requestObject)

The error handler when there is an error fetching items. This function should not be called directly and is used by simpleFetch.fetch().

Parameter Type Description
errorData Object
requestObject Object
fetch(request)

The simpleFetch mixin is designed to serve as a set of function(s) that can be mixed into other datastore implementations to accelerate their development.

The simpleFetch mixin should work well for any datastore that can respond to a _fetchItems() call by returning an array of all the found items that matched the query. The simpleFetch mixin is not designed to work for datastores that respond to a fetch() call by incrementally loading items, or sequentially loading partial batches of the result set. For datastores that mixin simpleFetch, simpleFetch implements a fetch method that automatically handles eight of the fetch() arguments -- onBegin, onItem, onComplete, onError, start, count, sort and scope The class mixing in simpleFetch should not implement fetch(), but should instead implement a _fetchItems() method. The _fetchItems() method takes three arguments, the keywordArgs object that was passed to fetch(), a callback function to be called when the result array is available, and an error callback to be called if something goes wrong. The _fetchItems() method should ignore any keywordArgs parameters for start, count, onBegin, onItem, onComplete, onError, sort, and scope. The _fetchItems() method needs to correctly handle any other keywordArgs parameters, including the query parameter and any optional parameters (such as includeChildren). The _fetchItems() method should create an array of result items and pass it to the fetchHandler along with the original request object -- or, the _fetchItems() method may, if it wants to, create an new request object with other specifics about the request that are specific to the datastore and pass that as the request object to the handler.

For more information on this specific function, see dojo/data/api/Read.fetch()

Parameter Type Description
request Object
Optional

The keywordArgs parameter may either be an instance of conforming to dojo/data/api/Request or may be a simple anonymous object that may contain any of the following:

{
    query: query-object or query-string,
    queryOptions: object,
    onBegin: Function,
    onItem: Function,
    onComplete: Function,
    onError: Function,
    scope: object,
    start: int
    count: int
    sort: array
}

All implementations should accept keywordArgs objects with any of

the 9 standard properties: query, onBegin, onItem, onComplete, onError scope, sort, start, and count. Some implementations may accept additional properties in the keywordArgs object as valid parameters, such as {includeOutliers:true}.

The query parameter

The query may be optional in some data store implementations. The dojo/data/api/Read API does not specify the syntax or semantics of the query itself -- each different data store implementation may have its own notion of what a query should look like. However, as of dojo 0.9, 1.0, and 1.1, all the provided datastores in dojo.data and dojox.data support an object structure query, where the object is a set of name/value parameters such as { attrFoo: valueBar, attrFoo1: valueBar1}. Most of the dijit widgets, such as ComboBox assume this to be the case when working with a datastore when they dynamically update the query. Therefore, for maximum compatibility with dijit widgets the recommended query parameter is a key/value object. That does not mean that the the datastore may not take alternative query forms, such as a simple string, a Date, a number, or a mix of such. Ultimately, The dojo/data/api/Read API is agnostic about what the query format.

Further note: In general for query objects that accept strings as attribute value matches, the store should also support basic filtering capability, such as (match any character) and ? (match single character). An example query that is a query object would be like: { attrFoo: "value"}. Which generally means match all items where they have an attribute named attrFoo, with a value that starts with 'value'.

The queryOptions parameter

The queryOptions parameter is an optional parameter used to specify options that may modify the query in some fashion, such as doing a case insensitive search, or doing a deep search where all items in a hierarchical representation of data are scanned instead of just the root items. It currently defines two options that all datastores should attempt to honor if possible:

{
    ignoreCase: boolean, // Whether or not the query should match case sensitively or not.  Default behaviour is false.
    deep: boolean   // Whether or not a fetch should do a deep search of items and all child
                    // items instead of just root-level items in a datastore.  Default is false.
}

The onBegin parameter.

function(size, request); If an onBegin callback function is provided, the callback function will be called just once, before the first onItem callback is called. The onBegin callback function will be passed two arguments, the the total number of items identified and the Request object. If the total number is unknown, then size will be -1. Note that size is not necessarily the size of the collection of items returned from the query, as the request may have specified to return only a subset of the total set of items through the use of the start and count parameters.

The onItem parameter.

function(item, request);

If an onItem callback function is provided, the callback function will be called as each item in the result is received. The callback function will be passed two arguments: the item itself, and the Request object.

The onComplete parameter.

function(items, request);

If an onComplete callback function is provided, the callback function will be called just once, after the last onItem callback is called. Note that if the onItem callback is not present, then onComplete will be passed an array containing all items which matched the query and the request object. If the onItem callback is present, then onComplete is called as: onComplete(null, request).

The onError parameter.

function(errorData, request);

If an onError callback function is provided, the callback function will be called if there is any sort of error while attempting to execute the query. The onError callback function will be passed two arguments: an Error object and the Request object.

The scope parameter.

If a scope object is provided, all of the callback functions (onItem, onComplete, onError, etc) will be invoked in the context of the scope object. In the body of the callback function, the value of the "this" keyword will be the scope object. If no scope object is provided, the callback functions will be called in the context of dojo.global(). For example, onItem.call(scope, item, request) vs. onItem.call(dojo.global(), item, request)

The start parameter.

If a start parameter is specified, this is a indication to the datastore to only start returning items once the start number of items have been located and skipped. When this parameter is paired with 'count', the store should be able to page across queries with millions of hits by only returning subsets of the hits for each query

The count parameter.

If a count parameter is specified, this is a indication to the datastore to only return up to that many items. This allows a fetch call that may have millions of item matches to be paired down to something reasonable.

The sort parameter.

If a sort parameter is specified, this is a indication to the datastore to sort the items in some manner before returning the items. The array is an array of javascript objects that must conform to the following format to be applied to the fetching of items:

{
    attribute: attribute || attribute-name-string,
    descending: true|false;   // Optional.  Default is false.
}

Note that when comparing attributes, if an item contains no value for the attribute

(undefined), then it the default ascending sort logic should push it to the bottom of the list. In the descending order case, it such items should appear at the top of the list.

fetchHandler(items,requestObject)

The handler when items are successfully fetched. This function should not be called directly and is used by simpleFetch.fetch().

Parameter Type Description
items Array
requestObject Object
fetchItemByIdentity(keywordArgs)

See dojo/data/api/Identity.fetchItemByIdentity()

Parameter Type Description
keywordArgs Object
filter(requestArgs,arrayOfItems,findCallback)
Parameter Type Description
requestArgs undefined
arrayOfItems undefined
findCallback undefined
getAttributes(item)

See dojo/data/api/Read.getAttributes()

Parameter Type Description
item dojo/data/api/Item
Returns:Array
getFeatures()

See dojo/data/api/Read.getFeatures()

Returns:undefined
getIdentity(item)

See dojo/data/api/Identity.getIdentity()

Parameter Type Description
item dojo/data/api/Item
Returns:undefined | null
getIdentityAttributes(item)

See dojo/data/api/Identity.getIdentityAttributes()

Parameter Type Description
item dojo/data/api/Item
Returns:null | Array
getLabel(item)

See dojo/data/api/Read.getLabel()

Parameter Type Description
item dojo/data/api/Item
Returns:undefined | number
getLabelAttributes(item)

See dojo/data/api/Read.getLabelAttributes()

Parameter Type Description
item dojo/data/api/Item
Returns:Array | null
getValue(item,attribute,defaultValue)

See dojo/data/api/Read.getValue()

Parameter Type Description
item dojo/data/api/Item
attribute attribute-name-string
defaultValue value
Optional
Returns:value
getValues(item,attribute)

See dojo/data/api/Read.getValues()

Parameter Type Description
item dojo/data/api/Item
attribute attribute-name-string
Returns:undefined
hasAttribute(item,attribute)

See dojo/data/api/Read.hasAttribute()

Parameter Type Description
item dojo/data/api/Item
attribute attribute-name-string
Returns:boolean
isItem(something)

See dojo/data/api/Read.isItem()

Parameter Type Description
something anything
Returns:boolean
isItemLoaded(something)

See dojo/data/api/Read.isItemLoaded()

Parameter Type Description
something anything
Returns:undefined
loadItem(keywordArgs)

See dojo/data/api/Read.loadItem()

Parameter Type Description
keywordArgs object
on(type,listener)
Defined by dojo/Evented
Parameter Type Description
type undefined
listener undefined
Returns:undefined
Error in the documentation? Can’t find what you are looking for? Let us know!