我有一些基于搜索查询过滤数组的代码。这很好,但是如果没有匹配到任何一个过滤器,我想运行一个函数。
过滤代码:
function filter() {
let filters = "";
let checkboxDiv = document.getElementById("checkboxes");
let inputs = checkboxDiv.getElementsByTagName("input");
let postcode = document.getElementById("postcodeInput").value;
let suburb = document.getElementById("suburbInput").value;
suburb = suburb.charAt(0).toUpperCase() + suburb.slice(1);
let capacity = document.getElementById("capacityInput").value;
let results = Object.keys(halls);
results.filter(key => {
if (postcode == halls[key]['Location'][3]['Postcode'] && suburb == "") {filters += "Postcode "; return true;}
if (suburb == halls[key]['Location'][1]['Suburb'] && postcode == "") {filters += "Suburb "; return true;};
if (capacity <= halls[key]['Room'][0]['Standing Capacity'] && capacity != "") {filters += "Capacity ";return true;}
return false
}).forEach(key => filterAll([halls[key]]));
}
如果filter语句返回false并运行函数,我如何“捕获”它?
在英语中:如果用户输入一个郊区,并且没有与之匹配的郊区,则运行该函数。
提前感谢:)
暂无答案!
目前还没有任何答案,快来回答吧!