我循环遍历列表中的行{/ 1}},并在每行上应用一组带$.each
的过滤器。我想跳过不匹配的行。它看起来像这样:
$.each
如果$.each(data, function(i, row) {
count = parseInt(row['n']);
year = row['year'];
if (options.filters) {
$.each(options.filters, function(filter, filtervalue) {
if (row[filter] != filtervalue) return true;
});
}
// Will only get here if all filters have passed
}
与给定过滤器不匹配,如何让嵌套$.each
循环跳过该行?
答案 0 :(得分:1)
如果至少有一个filtervalue
不匹配的过滤器,你想跳过一行吗?然后不要跳过 iff ,filtervalue
匹配至少一个过滤器。
$.each(data, function(i, row) {
count = parseInt(row['n']);
year = row['year'];
// if there are no filters, don't skip the row (right? ;-)
var skipRow = !!options.filters;
if (options.filters) {
$.each(options.filters, function(filter, filtervalue) {
if (row[filter] == filtervalue) {
skipRow = false;
}
});
}
if (skipRow) return true;
}