0

这是我的代码:

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

正如您从我上面的评论中看到的那样,数据在 my 中正确输出console.log(),但是当我尝试在其中使用它时,new Memory()它说它是“未定义的”。如何正确地用 JSON 数据填充我的 ComboBox?

4

1 回答 1

1

由于您已经提到了它的 json 数据,因此您还应该在代码中包含 handleAs: "json"。

dojo.xhrGet({

   url: "/api/products",
   handleAs: "json", ///
   load: function (result) {
   .....
   .....
   }
});
于 2013-08-29T20:09:06.030 回答