Javascript 用JSON填充dojo组合框
这是我的代码:Javascript 用JSON填充dojo组合框,javascript,combobox,dojo,Javascript,Combobox,Dojo,这是我的代码: dojo.xhrGet({ url: "/api/products", load: function (result) { require([ "dojo/store/Memory", "dijit/form/ComboBox", "dojo/domReady!" ], function (Memory, ComboBox) { console.log(result); // this outp
dojo.xhrGet({
url: "/api/products",
load: function (result) {
require([
"dojo/store/Memory", "dijit/form/ComboBox", "dojo/domReady!"
], function (Memory, ComboBox) {
console.log(result); // this outputs the data successfully...
var stateStore = new Memory({
data: result // but, this says it's "undefined"
});
var comboBox = new ComboBox({
id: "stateSelect",
store: stateStore,
searchAttr: "Name"
}, "stateSelect");
});
}
});
从我上面的评论中可以看出,数据在我的
控制台.log()
中正确输出,但是当我尝试在新内存()中使用它时,它说它是“未定义的”。我如何用JSON数据正确填充组合框?既然您提到了它的JSON数据,您还应该在代码中包含handleAs:“JSON”
dojo.xhrGet({
url: "/api/products",
handleAs: "json", ///
load: function (result) {
.....
.....
}
});