1

我看不出有什么问题,但错误控制台显示:“_21.store.fetch 不是函数”。组合框只是没有被填充。我尝试了 Memory 和 ItemFileWriteStore,两者都不起作用!怎么了?我正在使用 dojo 1.6.1 顺便说一句。代码如下:

<html>
<head>
<script type="text/javascript" src="dojo/dojo.js.uncompressed.js"></script>
<link rel="stylesheet" type="text/css" href="dojo/resources/dojo.css"></style>
<link rel="stylesheet" type="text/css" href="dijit/themes/claro/claro.css"></style>
<script type="text/javascript">
    dojo.require("dijit.form.ComboBox");
    dojo.require("dojo.store.Memory");
    dojo.require("dojo.data.ItemFileWriteStore");
    dojo.require("dojo.data.ItemFileReadStore");
</script>

<script type="text/javascript">
dojo.ready(function(){
    var rateStore, rate;

    rateStore = new dojo.store.Memory({
        data: [
            {id:1, name:"1 X"},
            {id:2, name:"2 X"},
            {id:4, name:"4 X"},
            {id:6, name:"6 X"},
            {id:8, name:"8 X"},
            {id:10, name:"10 X"}
        ]
    });
    /*
    rateStore =  new dojo.data.ItemFileWriteStore({
        data: {
            items:[
                {id:1, name:"1 X"},
                {id:2, name:"2 X"},
                {id:4, name:"4 X"},
                {id:6, name:"6 X"},
                {id:8, name:"8 X"},
                {id:10, name:"10 X"}
            ]
        }
    });
    */
    rate = new dijit.form.ComboBox({
        id: "rate",
        name: "rate",
        store: rateStore,
        searchAttr: name,
        style: "width:50px"
    }, dojo.byId("rate"));
    rate.startup();
});
</script>
</head>
<body class="claro">
<div id="rate"></div>
</body>
</html>
4

2 回答 2

1

在 1.6.1 中,ComboBox 不支持 store API。因此,您将需要使用 ItemFileReadStore 或 ItemFileWriteStore。

rateStore =  new dojo.data.ItemFileWriteStore({
    data: {
        identifier: 'id',
        label: 'name',
        items:[
            {id:1, name:"1 X"},
            {id:2, name:"2 X"},
            {id:4, name:"4 X"},
            {id:6, name:"6 X"},
            {id:8, name:"8 X"},
            {id:10, name:"10 X"}
        ]
    }
});

rate = new dijit.form.ComboBox({
    id: "rate",
    name: "rate",
    store: rateStore,
    style: "width:250px"
}, dojo.byId("rate"));
rate.startup();
于 2012-04-30T10:24:34.283 回答
0

试试这个:

rate = new dijit.form.ComboBox({
    id: "rate",
    name: "rate",
    store: rateStore,
    searchAttr: "name",
    style: "width:50px"
}, "rate").startup();
于 2012-04-30T06:02:02.117 回答