voidstate
voidstate

Reputation: 7990

How to Retrieve All Records from a Dojo/Store?

is there a built-in way to fetch all the records in a dojo/store (particularly a dojo/MemoryStore)? Something like:

store.query('*');

?

Upvotes: 2

Views: 1876

Answers (2)

Hackie
Hackie

Reputation: 125

The solution is simple. Call the query method of a Store instance.

store.query();

Here is the source code of dojo/store/util/SimpleQueryEngine. Version Dojo 1.8. As you see, it will always return True if query is undefined.

    switch(typeof query){
    default:
        ...

    case "object": case "undefined":
        var queryObject = query;
        query = function(object){
            for(var key in queryObject){
                var required = queryObject[key];
                if(required && required.test){
                    // an object can provide a test method, which makes it work with regex
                    if(!required.test(object[key], object)){
                        return false;
                    }
                }else if(required != object[key]){
                    return false;
                }
            }
            return true;
        };
        break;
    case "string":
        ...

    case "function":
        ...
}   
function execute(array){
    // execute the whole query, first we filter
    var results = arrayUtil.filter(array, query);

    ...
    ...

    return results;
}

It is necessary to read the dojo source code, if documentation is confused or missing. Hope the answer will be helpful. :)

Upvotes: 3

voidstate
voidstate

Reputation: 7990

It seems the answer is extremely simple. You just access the data property directly.

var allData = store.data;

This works for MemoryStores. I don't know if it would work for stores requiring remote loading of data.

Upvotes: 1

Related Questions