Skip to content

Conversation

kwangseng-lionstork
Copy link

Would like the ability to pass custom parameters to callback function so that we can share the same callback.

Eg.

                <model-select  :options="options"  @select="onSelect" :params="[1]">
                </model-select>
                <model-select  :options="options"  @select="onSelect" :params="[2]">
                </model-select>
        onSelect: function (item, id) {
            if (id == 1) {
                //do 1
            }
            else if (id == 2){
                //do 2
            }
        }

@moreta
Copy link
Owner

moreta commented Aug 10, 2018

Thank you for PR.

custom parameters are for parent component.
custom parameters nothing todo in ModelSelect Component.
So it useful but ..

If you want use one method for multiple component(like your eg),
extend options will be helpful.

ModelSelect's options can hold more objects keys not only value and text.

data () {
      return {
        // item1
        options: [
          { value: '1', text: 'aa' + ' - ' + '1', param: 1 },
          { value: '2', text: 'ab' + ' - ' + '2', param: 2 },
        ]
      }
    },
onSelect: function (item) {
            if (item.param == 1) {
                //do 1
            }
            else if (item.param == 2){
                //do 2
            }
        }

Or you can use ModelListSelect(sorry not clear component name)
ModelListSelect's list prop can set any object.
And specify optionValue prop for value, optionText prop for text.

@patocorrenti
Copy link

patocorrenti commented Jan 31, 2019

@moreta It doesn't solve the exact same problem.

I mean, if you add a param to the options array then the callback will depend on the selected option instead of the component who did the call.

I'm facing a problem by using the multi-select component inside a loop. All the components are calling the exact same function, but I need a way to differentiate them.

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

Successfully merging this pull request may close these issues.

3 participants