js 多条件 多数据筛选
作者:互联网
场景:前端多条件过滤
数据格式:[
{
color: "",
companyName: "济南宏益环境科技有限公司",
orgid: "370114",
remark: "111",
tag: "人工标记"
},
……
]
方法定义:
export function multiFilter(array, filters) { const filterKeys = Object.keys(filters) console.log(filterKeys); // filters all elements passing the criteria return array.filter((item) => { // dynamically validate all filter criteria return filterKeys.every(key => { //ignore when the filter is empty Anne if(!filters[key].length) return true return !!~item[key].indexOf(filters[key]) }) }) }vue调用 getList1() { this.currentPage = 1 this.pageSize = 10 // console.log(this.searchForm) //重新组装数据 let obj={ companyName:this.searchForm.companyName, tag:this.searchForm.tag || "", orgid:this.searchForm.orgid || "", } const arr = multiFilter(this.cloneData, obj) //调用方法 // console.log(arr); // arr.forEach(item=>{ // console.log(item.orgid); // }) this.tableData = arr },
标签:arr,return,key,js,filters,条件,console,筛选,log 来源: https://www.cnblogs.com/zhaohui9527/p/16643098.html