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

╄→гoц情女王★ 提交于 2020-01-03 18:55:53

问题


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

回答1:


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/



来源:https://stackoverflow.com/questions/11795779/dojo-how-to-get-json-attribute-from-dojo-data-itemfilereadstore

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!