4

我在 typeData 变量中有以下 JSON,然后将其放入 dojo.data.ItemFileReadStore。我需要知道的是如何检查status的值,它是设置为“成功”还是其他值。我无法弄清楚如何从 ItemFileReadStore 获取状态值,任何帮助将不胜感激。

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

1 回答 1

4

ItemFileReadStore不会处理数据对象的附加属性。但是,您可以扩展ItemFileReadStore以执行您需要的操作。您将覆盖“内部”方法,因此开发人员要小心。

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/

于 2012-08-04T02:17:39.310 回答