我在typeData变量中有以下 JSON,然后将其放入dojo.data.ItemFileReadStore.我需要知道的是如何检查状态的值,是设置为“成功”还是其他一些值.我无法弄清楚如何从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 });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/