Sum/Avg in a Dojo Data Store
I have a datastore : mystore. Say that it represents a list of students and their grades.
I want to represent a datagrid and a chart of those datas, but with a query : average grade of students which name begins with "B".
So I just need to create a sub-store with the right info. But I can't find this function in the doc.
Is it something like : mysubstore = new dojo.data.ItemFileRead({data: mydata}, *SOMEQUERY)
Can anyone help me with this ?
Well, I couldn't find smth like this but you can still write:
function createSubStorage(old_storage, query) {
new_storage = dojo.data.ItemFileWrite( ... ));
old_storage.fetch({
query: query,
onComplete: function(items, request) {
dojo.forEach(items, function(entry, i) {
new_storage.newItem(entry);
});
},
queryOptions: {
deep: true
}
});
return new_storage
}
oldStorage = new dojo.data.ItemFileRead( ... );
//...
newStorage = createSubStorage(oldStorage, query);
精彩评论