Skip to content

关于element UI 的input搜索下拉框的两种匹配方式

Notifications You must be signed in to change notification settings

fredfeng0326/inputsearch

Repository files navigation

inputsearch

input search function

querySearch(queryString, cb) {
      var restaurants = this.restaurants;
      var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
      // 调用 callback 返回建议列表的数据
      cb(results);
},
createFilter(queryString) {
      return (restaurant) => {
        return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
      };
}

这是例子的中算法。其实很简单,就是indexOf的简单应用。 但是这个===0只能从开头匹配。全字段匹配就要改成>-1

演示页面:https://fredfeng0326.github.io/inputsearch/ image image

Build Setup

# install dependencies
npm install

# serve with hot reload at localhost:8080
npm run dev

About

关于element UI 的input搜索下拉框的两种匹配方式

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published