Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to change options after async options load. #535

Open
43Laboratories opened this issue Sep 22, 2023 · 0 comments
Open

Unable to change options after async options load. #535

43Laboratories opened this issue Sep 22, 2023 · 0 comments

Comments

@43Laboratories
Copy link

The issue is when I load the initial options and make a query in this case i query NO1. I then update the options. After updating the options (clearing them) no1 still appears in the options until i use a non-cached query. So for example if I query o1 it will not show no1 in the options after clearing, because i did not query o1. I think the issue is caching or there might be errors in the code. Either way I am struggling to change the options properly using async mode.

I am simply trying to clear the options when this event is emitted. eventBus.$on('remove_all_options', this.changeOptions);

TreeSelect Component HTML

<div id="app" class="outerSelect">
  <div id="TS_1" class="TS_1" > 
  <treeselect v-model="value" :multiple="true" :options="optionsData" placeholder="Markets"
  :async="true"
  :load-options="loadOptions"
  ref="treeselect"
  > 



TreeselectJS
const simulateAsyncOperation = fn => {
  setTimeout(fn, 750)
}

 new Vue({
el: '#app',
data: {
  value: null,
  optionsData: [
  ], 
  },
created() {
  eventBus.$on('remove_all_options', this.changeOptions);
     },

Methods:

    methods: {
        
        triggerLoadOptions(){
            console.log("should be making a callback")
            this.$refs.treeselect.loadOptions({ callback: () => {} });
        },

method2 loads the initial options

  loadOptions(params) {
      
      console.log("load options called")
      console.log("called = ", window.glob_called)

    if (window.glob_called === true) {
      
      this.optionsData = []
    
      this.value = null;

 
      if (params && typeof params.callback === 'function') {
          console.log("Performing callback for update")
        params.callback(null, this.optionsData);
      }
    } else if (window.glob_called === false) {
    
      simulateAsyncOperation(() => {
        const initialOptions = [
          {
            id: 'No1',
            label: 'No1',
            children: [
              { id: 'suboption1', label: 'No1 Suboption 1' },
              { id: 'suboption2', label: 'No1 Suboption 2' },
            ],
          },
        ];

        this.optionsData = initialOptions
        if (params && typeof params.callback === 'function') {
          console.log("performing callback for load")
          params.callback(null, this.optionsData);
        }
      });
    }
  },

method3 changes the options

        changeOptions() {
     
      window.glob_called = true
      this.optionsData = [];
    this.v_search_query = null;
    this.$refs.treeselect.loadOptions({ callback: () => {} }); 
  },
},

});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant