question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] How to access to multiselect component ref

See original GitHub issue

I want to make a cascade componet A-multiselect with B-multiselect comp by a list dynamically

<multiselect v-for="item in list"
  v-ref:item.value    // not work in vue@1
>  
</multiselect>

how can i access the comp when it updated , selected or removed ? suggestion: can the multiselect comp can expose the refs when emit event ?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
shentaocommented, Aug 9, 2016

I will look into it after work. 😃

0reactions
theseawolvescommented, Aug 9, 2016

Sorry for the busy days and thank to your attention. I do have some confuse about data init , ajax and reactivity , need some good practices 😃

JSFilddle is here

//html dependent on vue@1 and vue-multiselect@latest
 <h3>Filters</h3>
  <multiselect 
      v-for="item in list"
      :id="item.name"
      :multiple="true"
      :hide-selected="true"
      v-ref:item
      :selected="item.selected"
      :options="item.options"
      :placeholder="item.name"
      @update="updateSelected">
    </multiselect>
    <hr>
    <!--for search results-->    
    <div>
      <table border=1 v-if="results.length>0" width="100%">
        <thead><tr><th></th><th >results</th></tr></thead>
        <tbody><tr v-for="item in results">
          <td v-text="$index+1"></td>
          <td v-text="item"></td>
        </tr></tbody>
      </table>
      <span v-else>no results</span>
    </div>
//javascript
new Vue({
  el: 'body',
  components: {
    multiselect: VueMultiselect.Multiselect
  },
  created:function(){
    //ajax
    var self = this
    setTimeout(function(){
            self.list = [
            {name:'A',selected: [],options: ['list_a', 'of_a', 'options_a']},
                {name:'B',selected: [],options: []},//is empty and according 'A' dynamic change
                {name:'C',selected: [],options: ['list_c', 'of_c', 'options_c']}
             ]
    },500)
  },
  data: {
      list:[],
      results:[]
  },
  computed: {
    condition () {
            let arr = []
            this.list.forEach(item=>{
            if(item.selected.length>0){
            arr.push(item.name + '=' + item.selected.join(','))
           }        
      })

      return arr
    }
  },
  ready: function() {
  },
  methods: {
    updateSelected (newSelected,id) {
            let item
        if (id === 'A') {
            // change 'B' according to 'A'
          const compA = this.queryCompById(this.$refs.item, id)
          const compB = this.queryCompById(this.$refs.item, 'B')

          item = this.queryListById(compB.id)
          item.selected = []
          item.options = item.options.length > 0 ? item.options.reverse() : ['list_b', 'of_b', 'options_b']
        }
        //update all multiselects
        item = this.queryListById(id)
        item.selected = newSelected

                //load results
        this.$nextTick(()=>{
          this.fetchData(this.condition)
        })
    },
    queryCompById (comps,id) {
      for (let i = 0; i < comps.length; i++) {
        let comp = comps[i]
        if (comp.id === id) return comp
      }
    },
    queryListById (id) {
      for (let i = 0; i < this.list.length; i++) {
        if (this.list[i].name === id) {
          return this.list[i]
        }
      }
    },
    fetchData (condition) {
     //ajax
        var self = this      
    setTimeout(function(){
            self.results= []
            self.condition.forEach(item=>{
            self.results.push(item)
            })
      },500)
    }

  }
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Retrieving value from <select> with multiple option in React
In case you want to use ref you can get selected values like this: ... Step 2 - Add the reference to `select`...
Read more >
Multi Select Variable Editor - Documentation | HotDocs
Displays a list of other components or templates (if there are any) that use the component you select. Double-clicking an item in the...
Read more >
Multi select/choices field populated via power automate
You can retrieve the labels/values for a Choices field by querying the StringMap table. This video goes through a step by step of...
Read more >
Dropdown | Dash for Python Documentation | Plotly
Multi-Value Dropdown. A dropdown component with the multi property set to True will allow the user to select more than one value at...
Read more >
Drill Down Question - Qualtrics
From the Data & Analysis tab, you can view and manage individual respondents' data. Compatible Visualizations. Visualizations are the graphs and tables you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found