Traker
Traker

Reputation: 2187

Dojo Select widget not populating contents from a datastore

I have been trying to connect to simply connect a datastore (ItemFileReadStore) to a dijit.form.Select widget and have been unable to. If I use the options field to populate it then the widget works fine but when I go to use the store field to populate it the widget appears but its contents are empty. The code that I am trying to use is below:

  var readStore = new dojo.data.ItemFileReadStore({
                            label: "label",
                            identifier: "value",
                            //items: nestedSortOptions1
                            items: [{label : "Lab1", value: "Val1"}]
                    });
  var sel1 = new dijit.form.Select({
                    id:"sel1",
                    name: "sel1",
                    required: true,
                    style: "width: 170px;",
                    //options: nestedSortOptions1
                    store: readStore
            },"sel1");

I assumed that you would make this widget "data-enabled" using the store field but I may be mistaken. If anyone can help it would be greatly appreciated. Thanks

Upvotes: 1

Views: 1863

Answers (1)

Ken Franqueiro
Ken Franqueiro

Reputation: 10559

You're on the right track, but in the case of your particular example posted, there are two problems:

Firstly, the properties you're passing to ItemFileReadStore should be further embedded inside a data attribute, i.e.:

var readStore = new dojo.data.ItemFileReadStore({
    data: {
        label: "label",
        identifier: "value",
        items: [
            { label: "Lab1", value: "Val1" }
        ]
    }
});

(See explanation of the data attribute on the reference guide page for ItemFileReadStore: http://www.dojotoolkit.org/reference-guide/dojo/data/ItemFileReadStore.html)

Secondly, you're neglecting to call sel1.startup() after instantiating the Select. Turns out startup is precisely where the Select fetches from the store.

(The startup method is called automatically in instances where you rely on dojo.parser to parse HTML-declared widget instances; it's also called automatically on child widgets of layout widgets when the layout widget's startup is called.)

Upvotes: 4

Related Questions