yeeen
yeeen

Reputation: 4945

Dojo Combo Box with error "store.fetch is not a function"

I don't see what's wrong, but the error console says: "_21.store.fetch is not a function". The combo box just doesn't get populated. I tried both Memory and ItemFileWriteStore, both doesn't work! What's wrong? I am using dojo 1.6.1 btw. The code is as below:

<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>

Upvotes: 1

Views: 1542

Answers (2)

Craig Swing
Craig Swing

Reputation: 8162

In 1.6.1, the ComboBox does not support the store API. So you will need to use the ItemFileReadStore or 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();

Upvotes: 1

maialithar
maialithar

Reputation: 3123

Try this:

rate = new dijit.form.ComboBox({
    id: "rate",
    name: "rate",
    store: rateStore,
    searchAttr: "name",
    style: "width:50px"
}, "rate").startup();

Upvotes: 0

Related Questions