• getIdentity
• queryEngine
• transaction
• getChildren
• getMetadata
The query method is very interesting. It can be used to query a store which returns an array of
objects that matched the query. The return is actually a Dojo NodeList. This returned array has a
number of methods on it including:
• forEach()
• map()
• filter()
• length
The query expression for the query is an object which has properties corresponding to the property
being sought. For example:
myStore.query({name: "Neil"})
will return all the objects in the store which have a name property equal to "Neil". To return all
items in the list, pass in an empty object ({}). If the parameter to query is a function then the query
will pass the function each item in the store and the result will be only those items that pass a test.
The second parameter to query is an object with properties as follows:
• start – Starting offset
• count – The number of objects to return
• sort – An array of objects where each object is a definition of how the sort is to be
performed. An instance of one of these objects will contain the following properties:
◦ attribute – The name of the attribute to sort upon
◦ descending – A boolean indicating whether we want ascending or descending sorting
It is possible to write our own function to perform the queryEngine task. The queryEngine
property of a store must be a function that takes the same parameters as the query. Your own
function does not do the work immediately. Instead, what it does is return a function which takes
an array as input and performs this specialized query.
The result from the query includes a method called:
forEach(function(entry) { … } )
which allows us to execute a function for each entry returned from the query.
See also:
• SitePen – Dojo Object Store – 1.9
• dojo/store – 1.9
dojo/store/Memory
The dojo/store/Memory implements the Dojo object store API. It is used to access store
Page 200
Comentários a estes Manuais