I have the following code below, which will create a FilteringSelect and set the first selected item:
// Store initialization:
var jsonStore = custom.store.JsonRest({ ... });
var memoryStore = dojo.store.Memory();
var myStore = dojo.store.Cache( jsonStore, memoryStore);
var dataStore = custom.store.MyObjStore({ objectStore: myStore, ... });
// FilteringSelect initialization:
var fsel = new dijit.form.FilteringSelect({
id: 'fsel',
searchAttr: 'id',
store: dataStore
});
// Setting the first item on FilteringSelect, retrieved from store objects
fsel.store.fetch({ query: {id:""},
onComplete: function (items, request) {
var val = "";
if (items.length>0) val = items[0].id;
fsel.set('value', val);
}
});
First problem is that, if the
items[0].id = 0, this item is not set on FilteringSelect.fsel.store.fetch({ ... })queries the server, which is ok. The problem is that the retrieved items are not kept in memory, or they are, but are not retrieved by FilteringSelect on the next event. I mean, when I click the first time on FilteringSelect's dropdown another query is sent to server to get the items, the following times they get from memory.
Could anyone help me to solve these two problems?
Note: I'm using Dojo version 1.7.2 (27913).
val = items[0].id[0];should do it. Store values are presented as arrays. - undefinedidis a property of object, and I'm getting the first item on the store, soitems[0]. I forgot to mention the version, I'm using Dojo 1.7.2 (27913). - Ivo Silva