search(calVal) { // 聊天室左侧联系人搜索匹配
this.MatchingSuccess = [];
this.RecentlyTxt.forEach((item,index)=>{
if ( item.Name.toLowerCase().indexOf(calVal) != -1 ) { // 判断是否含有匹配的值;
this.MatchingSuccess.push(item);
}
});
console.log(this.MatchingSuccess);
},
注: item.Name.toLowerCase().indexOf(calVal) != -1 中的 toLowerCase()是不区分大小写搜索的关键; 整个搜索关键在于利用字符串的 indexOf()方法进行依次匹配,匹配成功就压入到需要显示的数组中去;