Question

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);
  }
});
  1. First problem is that, if the items[0].id = 0, this item is not set on FilteringSelect.

  2. 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).

Was it helpful?

Solution

After a talk with someone from dojo, I solved my question the following way:

  1. Switching to the last version (1.8.1), fixed this first issue.

  2. Using the memoryStore on FilteringSelect, instead of cache store (myStore), will just make use of objects in memory. Making a query on myStore (cache store) will load the objects from server to memory.

// Store initialization:
var jsonStore = new JsonRest({ ... });
var memoryStore = new Memory();
var myStore = new Cache(jsonStore, memoryStore);
// Note: ObjectStore was removed.

// FilteringSelect initialization:
var fsel = new FilteringSelect({
         id: 'fsel',
         searchAttr: 'id',
         store: memoryStore
       });

// Setting the first item on FilteringSelect and loading items to memory
when (myStore.query({id:""}),
  function (items, request) {
    var val = "";
    if (items.length>0) val = items[0].id;
    fsel.set('value', val);
  }
);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top