search

Home  >  Q&A  >  body text

vue3-select2-component, filter by first character

<p>I need the filtering option ("Sortizer" in settings works fine) but I can't get the modelValue from the "Input" where I put any symbols. How do I get the first symbol I entered? Only works for event @select, but it is not suitable for this task</p> <pre class="brush:php;toolbar:false;"><Select2 value="modelValue" @input="(e) => modelValue = e.target.value" :settings="select2Settings" /> select2Settings: { sorter: function (results) { return results.filter((item) => item.text.startsWith(modelValue)) } }</pre> <p>I also tried using event @change but it didn't work at all In this demo</p>
P粉921130067P粉921130067486 days ago598

reply all(1)I'll reply

  • P粉466909449

    P粉4669094492023-09-01 09:15:53

    everything is normal!

    select2Settings: {
        matcher: function (params, data) {
          if (!params.term)
            return data;
          if (data.text.toLowerCase().startsWith(params.term.toLowerCase()))
            return data;
          else
            return null;
        },
    }

    reply
    0
  • Cancelreply