Dojo如何从dojo.data.ItemFileReadStore获取JSON属性 [英] Dojo how to get JSON attribute from dojo.data.ItemFileReadStore
问题描述
我在typeData变量中具有以下JSON,然后将其放入dojo.data.ItemFileReadStore中。我需要知道的是如何检查状态的值,是否设置为成功或其他一些值。我无法弄清楚如何从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 });
推荐答案
ItemFileReadStore
不会处理数据对象的附加属性。但是,您可以扩展 ItemFileReadStore
以执行所需的操作。你将会覆盖'内部'的方法,所以这是开发人员注意的。
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/
这篇关于Dojo如何从dojo.data.ItemFileReadStore获取JSON属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!