vue-search-select icon indicating copy to clipboard operation
vue-search-select copied to clipboard

- Add ability to pass custom parameters to callback functions

Open kwangseng-lionstork opened this issue 7 years ago • 2 comments

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
            }
        }

kwangseng-lionstork avatar Aug 10 '18 04:08 kwangseng-lionstork

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.

moreta avatar Aug 10 '18 08:08 moreta

@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.

patocorrenti avatar Jan 31 '19 15:01 patocorrenti