过滤表达式与过滤对象
过滤器表达式不能包含过滤器对象。这是非常重要的。如果你决定使用 Filter Expression 形成过滤器,则使用字符串数组数组。以下语法错误 :
// WRONG!!!
var f1 = search.createFilter({
name: 'mainline',
operator: search.Operator.IS,
values: 'T'
});
var f2 = search.createFilter({
name: 'type',
operator: search.Operator.ANYOF,
values: ['VendBill','VendCred']
});
// here you will receive an error message
var s = search.create({
type : 'transaction',
filters : [ f1, 'and', f2 ] // f1,f2 are Filter Objects, instead of string arrays
});
相反,使用正确的 :
// CORRECT!!!
var f1 = ['mainline', search.Operator.IS, 'T'];
var f2 = ['type', search.Operator.ANYOF, ['VendBill','VendCred'] ];
var s = search.create({
type : 'transaction',
filters : [ f1, 'and', f2 ]
});
或者如果你想继续使用 Filter Objects 方法,传递一组过滤器对象,并忘记运算符’AND’,‘OR’,‘NOT’。它将始终是 AND
// correct, but not useful
var f1 = search.createFilter({
name: 'mainline',
operator: search.Operator.IS,
values: 'T'
});
var f2 = search.createFilter({
name: 'type',
operator: search.Operator.ANYOF,
values: ['VendBill','VendCred']
});
var s = search.create({
type : 'transaction',
filters : [ f1, f2 ] // here you have array of Filter Objects,
// filtering only when all of them are TRUE
});