form.on('submit(search)', function (data) {
var name = data.field.searchName;
var code = data.field.searchCode;
var type = formSelects.value('typeSelect', 'val'); // 多选框
var typeArray = [];
if (type != "") {
typeArray = type.split(',');
}
var nameList = [];
var codeList = [];
var typeList = [];
var wrapperList = [];
layerGroupRoot.forEach(function (item) {
if (!isEmpty(item.name) && name != "" && item.name.indexOf(name) > -1) {
nameList.push(item);
}
if (!isEmpty(item.code) && code != "" && item.code.indexOf(code) > -1) {
codeList.push(item);
}
if (!isEmpty(item.type) && typeArray.length != 0 && typeArray.includes(item.type)) {
typeList.push(item);
}
})
if (nameList.length != 0) {
wrapperList.push(nameList);
}
if (codeList.length != 0) {
wrapperList.push(codeList);
}
if (typeList.length != 0) {
wrapperList.push(typeList);
}
if (wrapperList.length == 0) {
if(name == "" && code == "" && typeArray.length == 0){
initTable(layerGroupRoot); // 未填写查询条件则查询所有
}else{
initTable(wrapperList); // 填写查询条件但没找到
}
} else { // 取交集
var selectIdList = [];
wrapperList[0].forEach(function (item) {
selectIdList.push(item.id);
});
for (var i = 0; i < wrapperList.length - 1; i++) {
var tempIdList = [];
wrapperList[i + 1].forEach(function (item) {
if (selectIdList.includes(item.id)) {
tempIdList.push(item.id);
}
});
selectIdList = tempIdList;
}
var selectList = [];
wrapperList[0].forEach(function (item) {
if (selectIdList.includes(item.id)) {
selectList.push(item);
}
});
initTable(selectList);
}
});
前端对表格数据进行条件查询过滤
于 2022-07-23 09:38:27 首次发布