实现模糊查询主要用到一下方法
1.filter() 创建一个新的数组,新数组中的元素是通过检查指定数组中符合条件的所有元素
filter() 不会对空数组进行检测并且不会改变原始数组。
2.indexOf() 返回指定字符在字符串中第一次出现处的索引,如果此字符串中没有这样的字符,则返回 -1
3.toUpperCase() 将字符串str中的字符都转换为大写
4.toLowerCase() 将字符串str中的字符都转换为小写
实例
区分大小写
let option = this.parentList.filter(item=>{
if(item.orderNo.indexOf(this.searchOrderNo) > -1){
return true;
}
});
不区分大小写
let option = this.parentList.filter(item=>{
if(item.orderNo.toUpperCase().indexOf(this.searchOrderNo.toUpperCase()) > -1){
return true;
}
});
或
let option = this.parentList.filter(item=>{
if(item.orderNo.toLowerCase().indexOf(this.searchOrderNo.toLowerCase()) > -1){
return true;
}
});
*** 使用大写(小写)转换使字符统一