我想为具有多个条件的数据源构建过滤器。我发现了这个线程(HERE),这些人几乎有同样的问题,但我想在我的两个操作之间做一个 OR 而不是 AND。
到目前为止,我有代码:
var filter = { logic: "OR", filters: [] };
var filterProduct = { logic: "AND", filters: [] };
var supplierValue = dropdownSupplier.value();
if (supplierValue != "00000000-0000-0000-0000-000000000000") {
filterProduct.filters.push({ field: "SupplierId", operator: "eq", value: supplierValue });
}
var categoryValue = dropdownCategory.value();
if (categoryValue != "00000000-0000-0000-0000-000000000000") {
filterProduct.filters.push({ field: "CategoryId", operator: "eq", value: categoryValue });
}
var typeValue = dropdownType.value();
if (typeValue != "00000000-0000-0000-0000-000000000000") {
filterProduct.filters.push({ field: "TypeId", operator: "eq", value: typeValue });
}
var filterSelect = { logic: "OR", filters: [] };
filterSelect.filters.push({ field: "Id", operator: "eq", value: "00000000-0000-0000-0000-000000000000" });
filter.filters.push(filterProduct);
filter.filters.push(filterSelect);
dropdownProduct.dataSource.query({ filter: filter });
事实上,我想要做的是:(filterProduct)或(filterSelect)但如果我没有在变量过滤器中使用“逻辑”,过滤器将是一个“AND”。
非常感谢
编辑:有一个 jsFiddle 接近我想要做的,但使用“AND”:示例在此示例中,过滤器是:[ {[ Freight = 11.61 OR Freight = 51.30 ]} AND {[ City startswith "Charleroi" ]} ]
但我想要一些类似的东西:[ {[ Freight = 11.61 OR Freight = 51.30 ]} OR {[ City startswith "Charleroi" ]} ]