开发者

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜