zoukankan      html  css  js  c++  java
  • PinyinMatch实现拼音匹配,分词、缩写、多音字匹配能力

    参考https://www.npmjs.com/package/pinyin-match

    npm install pinyin-match --save

    const PinyinMatch require('pinyin-match');
    let test '123曾经沧海难为水除却巫山不是云'
    PinyinMatch.match(test'23曾');// [1, 3]
     
    案例1:

      <el-form-item label="控制方案">

          <el-select v-model="lngcontrolplanid" :placeholder="请输入" :filter-method="selectFilter" filterable @focus="onFocus">
            <el-option
              v-for="(item, index) in controlPlanList"
              :key="item.lngcontrolplanid"
              :value-key="item.lngcontrolplanid"
              :label="item.strcontrolplanname"
              :value="item.lngcontrolplanid"
            />
          </el-select>
        </el-form-item>
    <script>
    import pinyinMatch from 'pinyin-match'
    methods: {
    //聚焦时显示全部数据
        onFocus() {
          this.controlPlanList = this.copyControlPlanList
        },
        selectFilter(val) {
          if (val) {
            this.controlPlanList = this.copyControlPlanList.filter((item) => {
              return PinyinMatch.match(item.strcontrolplanname, val) //(需要过滤的名称,输入的关键词)
            })
          } else {
            this.controlPlanList = this.copyControlPlanList
          }
        },
    }
    </script>
     
    案例2
    <el-form-item label="出差地点" prop="districtIds">
    <el-cascader
          ref="areaNames"
          v-model="disValue"
          :options="districtAll"
          :props="{
            label: 'treedataname',
            value: 'treedataid',
            children: 'childList'
          }"
          :collapse-tags="collapseTags"
          filterable
          :filter-method="filterMethod"
        />
    </el-form-item>
    <script>
    import pinyinMatch from 'pinyin-match'
    methods: {
        filterMethod(node, keyword) {
          return pinyinMatch.match(node.text, keyword)
        }
    }
    </script>
  • 相关阅读:
    20171012
    BZOJ[2563] 阿狸和桃子的游戏
    BZOJ[1028] [JSOI2007]麻将
    BZOJ[1972] [Sdoi2010]猪国杀
    BZOJ[1033] [ZJOI2008] 杀蚂蚁antbuster
    P5651 基础最短路练习题
    P3047 [USACO12FEB]Nearby Cows G
    P6190 魔法
    P2391 白雪皑皑 / BZOJ 2054 疯狂的馒头
    CSP 2020 J/S 初赛游记
  • 原文地址:https://www.cnblogs.com/hellofangfang/p/10906986.html
Copyright © 2011-2022 走看看