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>
  • 相关阅读:
    Spring MVC @RequestMapping注解详解
    (转)Cesium教程系列汇总
    spring boot +mybatis(通过properties配置) 集成
    SpringBoot2.0之四 简单整合MyBatis
    在Windows下使用Git+TortoiseGit+码云管理项目代码
    TortoiseGit之配置密钥
    Spring Boot 学习之路二 配置文件 application.yml
    SpringBoot学习笔记(2) Spring Boot的一些配置
    【入门】Spring-Boot项目配置Mysql数据库
    Spring 的application.properties项目配置与注解
  • 原文地址:https://www.cnblogs.com/hellofangfang/p/10906986.html
Copyright © 2011-2022 走看看