Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @action.bound
  2.   setIsDefaultOptions(ref){
  3.     if(ref !== null){
  4.       featureServices.getDistinctOptionName().then(json => {
  5.         ref.setState(Object.assign(ref.state, {loadedOptions : json, defaultOptions: true}));})
  6.  
  7.         ref.loadOptions("",function (options) {
  8.  
  9.           ref.setState({ defaultOptions : options||[],inputValue: ref.state.inputValue});
  10.          
  11.          let selectValuesHasChanged = false;
  12.          let newValues = ref.state.loadedOptions;
  13.          ref.state.loadedOptions.forEach((el, currIndex) => {
  14.             let found = options.find(option => option.id === el.id);
  15.             if(found === undefined) {
  16.                 newValues.splice(currIndex, 1);
  17.                 selectValuesHasChanged = true;
  18.             }
  19.         }) ;
  20.         selectValuesHasChanged = true;
  21.         if(selectValuesHasChanged) {
  22.           // Set 'all' by default
  23.           if(newValues.length === 0) {
  24.               newValues.push({id: 'all', value: 'All'});
  25.           }
  26.           ref.select.select.select.setValue(newValues);
  27.         }
  28.         });
  29.     }
  30.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement