Vue-select: How to pass extra params to the events?

Created on 28 Nov 2017  路  6Comments  路  Source: sagalbot/vue-select

I have a case where I am using this plugin inside a table and I need to pass the row index to the events:

:on-search="getItems"
:on-change="setItemID"

How can we achieve this?

Most helpful comment

@arivera12 I ran into this same problem and was able to resolve it with currying.

Untested basic example:

<row ...
  <v-select :value="theCurrentValue" :options="theOptions"
                  :on-change="(selected) => updateSelected(selected, theCurrentValue)"
                  :getOptionLabel="labelFromRow"
                  label="name">
</row>

Here I capture the entire theCurrentValue in the function scope and when the anonymous "selected" function is called I can access the theCurrentValue value.

Hope that helps!

All 6 comments

Wondering the exact same thing. Have a table with multiple selects and need to know which one was changed. Want to pass an index through the :on-change method

Unless there's some Vue magic that I'm not up to date on - I think the only way to achieve this is to provide the VM instance as a parameter to every event that the component emits.

@arivera12 I ran into this same problem and was able to resolve it with currying.

Untested basic example:

<row ...
  <v-select :value="theCurrentValue" :options="theOptions"
                  :on-change="(selected) => updateSelected(selected, theCurrentValue)"
                  :getOptionLabel="labelFromRow"
                  label="name">
</row>

Here I capture the entire theCurrentValue in the function scope and when the anonymous "selected" function is called I can access the theCurrentValue value.

Hope that helps!

@redijedi it works, thanks for your solution!

i need send row variable in onSearch

                            <v-select label="name" :filterable="false" :options="row.account_list" @search="onSearch(row)" dir="rtl" v-model="row.account">
                                <template slot="no-options">
                                    type to search GitHub repositories..
                                </template>
                                <template slot="option" slot-scope="option">
                                    <div class="d-center">
                                        ({{option.code}}) {{ option.name }}
                                    </div>
                                </template>

                            </v-select>

This Works too .

image

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pud1m picture pud1m  路  3Comments

davidalvarezr picture davidalvarezr  路  3Comments

rafalolszewski94 picture rafalolszewski94  路  3Comments

FrancescoMussi picture FrancescoMussi  路  3Comments

manjunath-coachthem picture manjunath-coachthem  路  3Comments