Select2 custom data fetch when user starts typing in search bar. (BackboneJS / Marionette collection) SELECT2

92 Views Asked by At

I am using SELECT2 in BackboneJS/Marionette. Right now following is flow: Current: From parent, call FETCH method of COLLECTION. When fetch is completed then send this COLLECTION to a new VIEW and display drop down (SELECT2)

New Requirement: Now need to convert this data fetch at run-time. When user types in search bar of SELECT2, ajax call should be made and returned data needs to be converted to Marionette collection and then rendered in drop-down.

For this, i tried to implement this example.

Now problem is that data is fetched (visible in network tab), but drop-down remains empty (and there is no error/exception):

Added following code in _SELECTOR.prototype.settings.extend

ajax: {
   url: API_PATH + "testingvalues2",
   dataType: 'json',
   delay: 1000,
   minimumInputLength: 1,
   cache: true,
   data: function (params) {
      var query = {
         filter: params.term
      };
      console.log("query: ", query);
      return query;
   },
   processResults: function (data) {
      console.log("data : ", data);
      console.log("this>>", this);

      let newCollection = new DropdownDataCollection();
      for(let dataItem of data){
         let item = new DropdownValueEntity (dataItem);
         newCollection.add(item);
      }
      return {results : newCollection};
   }
},
0

There are 0 best solutions below