0
votes

Is there a way to instantiate a FilteringSelect without having it make an ajax call to the server? I have all of the information I need on page load for the object that is currently selected, it makes no sense to have to make another call back to the server for to populate the FilteringSelect with data that I already have. Ideally I'd like to instantiate the FilteringSelect with an object instead of the id.

2

2 Answers

0
votes

If you already have data, then all you need to do is to create a store and use that with FilteringSelect

For ex: you can create a store like

var stateStore = new dojo.store.Memory({
        data: [
            {name:"Alabama", id:"AL", timeStamp:"1211753600"},
            {name:"Alaska", id:"AK", timeStamp:"1211753601"},
            {name:"American Samoa", id:"AS", timeStamp:"1211753602"},
            {name:"Arizona", id:"AZ", timeStamp:"1211753603"},
            {name:"Arkansas", id:"AR", timeStamp:"1211753604"},
            {name:"Armed Forces Europe", id:"AE", timeStamp:"1211753605"},
            {name:"Armed Forces Pacific", id:"AP", timeStamp:"1211753606"},
            {name:"Armed Forces the Americas", id:"AA", timeStamp:"1211753607"},
            {name:"California", id:"CA", timeStamp:"1211753608"},
            {name:"Colorado", id:"CO", timeStamp:"1211753609"},
            {name:"Connecticut", id:"CT", timeStamp:"1211753610"},
            {name:"Delaware", id:"DE", timeStamp:"1211753611"}
        ], idProperty: "timeStamp"
    });

and then assign the store to FilteringSelect

 var filteringSelect = new FilteringSelect({
        id: "stateSelect",
        name: "state",
        store: stateStore,
        searchAttr: "name"

    }, "stateSelect").startup();
0
votes

I have many situations where I have current value available for the FilteringSelect, but not the full store, and like you I was having all these useless ajax calls to get data that I already had.

The problem is that FilteringSelect's set method calls the FilteringSelect's store.get() function, which in the case of dojo/store/JsonRest (which I am assuming is what you use) always issues the ajax call.

In my case, I ended up with my own version of JsonRest which modifies the get method to by-pass the ajax call if the data is already available, which solved the problem.

I cannot think right now of another workable solution.

Find below a template for an extended JsonRest that should help (did not test though):

define(["dojo/_base/declare", "dojo/store/JsonRest"], function(declare, JsonRest){
  return declare(JsonRest, {
    get: function(id, options){
        if (<name for id is known>){
            return <name for id>;
        }else{
            return this.inherited(arguments);
        }
  });
});

jc