Karl
Karl

Reputation: 149

Dojo how to get JSON attribute from dojo.data.ItemFileReadStore

I have the below JSON in the typeData variable that is then put into a dojo.data.ItemFileReadStore. What I need to know is how to check the value of status, was it set to "success" or some other value. I've not been able to figure out how to get the value of status from a ItemFileReadStore, any help would be greatly appreciated.

    var typesData = {
        status: "success",
        label: "name",
        identifier: "value",
        items: [
            {value: 3, name: "Truck"},
            {value: 8, name: "Van"},
            {value: 6, name: "Car"},
            {value: 7, name: "Scooter"}
        ]
    };
var test = new dojo.data.ItemFileReadStore({ data: typesData });

Upvotes: 4

Views: 1947

Answers (1)

Craig Swing
Craig Swing

Reputation: 8162

The ItemFileReadStore will not handle additional attributes on the data object. However, you can extend the ItemFileReadStore to do what you need. You will be overriding 'internal' methods, so it's developer beware.

dojo.declare("MyCustomStore", [Store], {
    _getItemsFromLoadedData: function(/* Object */ dataObject){
        this.serverStatus = dataObject.status;                     
        this.inherited(arguments);                            
    }
});

var typesData = {
    status: "success",
    label: "name",
    identifier: "value",
    items: [
        {value: 3, name: "Truck"},
        {value: 8, name: "Van"},
        {value: 6, name: "Car"},
        {value: 7, name: "Scooter"}
    ]
};
var test = new MyCustomStore({ data: typesData });
test._forceLoad(); // forces the processing of the data object

console.debug(test.serverStatus);

http://jsfiddle.net/cswing/dVGSc/

Upvotes: 4

Related Questions