前端拼音(汉字)检索,好用的插件 pinyin-match
好用的前端拼音检索插件(汉字也可检索),无需请求后端接口,只需针对当前已获取的数据源进行操作,对符合条件的数据进行返回显示,即可完成拼音检索
安装插件pinyin-match
npm install pinyin-match --save
js引入
在需要使用的文件位置进行引入
import PinyinMatch from ‘pinyin-match’;
能够实现的方法
let test = ‘123曾经沧海难为水除却巫山不是云’
PinyinMatch.match(test, ‘23曾’); // [1, 3]
PinyinMatch.match(test, ‘cjc’) // [3, 5]
PinyinMatch.match(test, ‘cengjingcanghai’) // [3, 6]
PinyinMatch.match(test, ‘cengjingcangha’) // [3, 6]
PinyinMatch.match(test, ‘engjingcanghai’) // false
PinyinMatch.match(test, ‘zengjingcang’) // [3, 5]
PinyinMatch.match(test, ‘sdjkelwqf’) // false
PinyinMatch.match(test, ‘zengji ng cang’) // [3, 5]
PinyinMatch.match(test, ‘zengji ng cangsdjfkl’) // false
PinyinMatch.match(’ 我 爱你 中 国 ', ‘nzg’) // [6, 12]
PinyinMatch.match(’ 我 爱你 中 国 ', ‘爱你中’) // [5, 8]
PinyinMatch.match(‘發’, ‘fa’) // [0, 0]
一些地址
pinyin-match的github 地址
https://github.com/xmflswood/pinyin-match
在线演练地址
http://laosep.top/pinyin-match;
具体实现文档
https://juejin.cn/post/6844904161461403661
更多推荐
所有评论(0)