使用JSON填充dojo ComboBox

时间:2013-08-29 19:44:22

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

从上面的评论中可以看出,数据在console.log()中正确输出,但当我尝试在new Memory()中使用时,它表示“未定义”。如何使用JSON数据正确填充我的ComboBox?

1 个答案:

答案 0 :(得分:1)

因为你已经提到过它的json数据,你还应该在代码中包含handleAs:“json”。

dojo.xhrGet({

   url: "/api/products",
   handleAs: "json", ///
   load: function (result) {
   .....
   .....
   }
});