我正在加载 JSON 数据并将其填充到选择标签上
我为此使用DOJO,我必须使用dojo,
请告诉我出了什么问题
我面临的问题是,在 JSON 中 GetStatesResult 用于声明数组但它不起作用,它只有在我使用项目代替 GetStatesResult 时才有效
dojo.ready(function() {
var stateStore = new dojo.data.ItemFileReadStore({
url : "http://localhost:8080/MobilePro/states.json"
});
function completed(GetStatesResult) {
var ref = dom.byId("stateSelect");
for ( var i = 0; i < GetStatesResult.length; i++) {
var node = domConstruct.create("option", {value: stateStore.getValue(GetStatesResult[i], "Value"), label: stateStore.getValue(GetStatesResult[i], "Desc")});
domConstruct.place(node, ref, "last");
}
}
function error(errData, request) {
console.log("Failed in loading data.");
}
stateStore.fetch({
onComplete : completed,
onError : error
});
});
这是 JSON
{
"GetStatesResult": [
{
"Desc": "--Select--",
"Value": "-1"
},
{
"Desc": "Alaska",
"Value": "AK"
},
{
"Desc": "Alabama",
"Value": "AL"
},
{
"Desc": "Arkansas",
"Value": "AR"
},
{
"Desc": "Arizona",
"Value": "AZ"
}
]
}