发布:2024/12/12 22:55:33作者:管理员 来源:本站 浏览次数:47
list中存放的对象:
public class Msg
{
public int Id { get; set; }
public string key { get; set; }
public string value { get; set; }
public string mark { get; set; }
public string node { get; set; }
public List<Msg> children { get; set; }
}
参数:
list:遍历对象;
keyWord:搜索条件;
attribute['value','mark']:需要检索的字段;
testQuery(list, keyWord, attribute = []) {
const reg = new RegExp(keyWord) // 创建正则表达式
const arr = []
for (let i = 0; i < list.length; i++) {
let isFind = false;
for (let j = 0; j < attribute.length; j++) {
if (list[i][attribute[j]]) {
isFind = reg.test(list[i][attribute[j]]);
if (isFind) {
arr.push(list[i]);
break;
} else if ("" != list[i]['children']) {
for (let l = 0; l < list[i]['children'].length; l++) {
for (let k = 0; k < attribute.length; k++) {
if ("" != list[i]['children'][l][attribute[k]]) {
isFind = reg.test(list[i]['children'][l][attribute[k]])
if (isFind) {
let arr2 = [];
arr2.push(list[i]['children'][l]);
list[i].children = arr2;
list[i]._showChildren = true;
arr.push(list[i]);
break
}
}
}
}
}
}
}
}
this.msg = arr;
this.total = this.msg.length;
//console.log(arr)
//console.log(this.total)
this.changePage(1);
//return arr
},
'
© Copyright 2014 - 2024 柏港建站平台 ejk5.com. 渝ICP备16000791号-4