@progress/kendo-data-query FilterDescriptor 运算符函数签名
@progress/kendo-data-query FilterDescriptor operator function signature
根据 the docs,FilterDescriptor
的 operator
属性可以是一个函数。
filterDescriptor.d.ts
/**
* A basic filter expression. Usually a part of [`CompositeFilterDescriptor`]({% slug api_kendo-data-query_compositefilterdescriptor %}).
*
* For more information, refer to the [`filterBy`]({% slug api_kendo-data-query_filterby %}) method.
*/
export interface FilterDescriptor {
/**
* The field of the data item to which the filter operator is applied.
*/
field?: string | Function;
/**
* The filter operator (comparison).
*
* The supported operators are:
* * `"eq"` (equal to)
* * `"neq"` (not equal to)
* * `"isnull"` (is equal to null)
* * `"isnotnull"` (is not equal to null)
* * `"lt"` (less than)
* * `"lte"` (less than or equal to)
* * `"gt"` (greater than)
* * `"gte"` (greater than or equal to)
*
* The following operators are supported for string fields only:
* * `"startswith"`
* * `"endswith"`
* * `"contains"`
* * `"doesnotcontain"`
* * `"isempty"`
* * `"isnotempty"`
*/
operator: string | Function;
/**
* The value to which the field is compared. Has to be of the same type as the field.
*/
value?: any;
/**
* Determines if the string comparison is case-insensitive.
*/
ignoreCase?: boolean;
}
我在互联网上找不到任何关于 FilterDescriptor.operator
的函数签名的信息。当然,因为 Kendo 不是开源的,我不能简单地检查他们的代码。
通过一些日志记录,我明白了。
export interface FilterDescriptor {
// ...
operator: string | ((fieledValue: any, filterValue: any) => boolean);
}
因此,如果您有一个带有名称的对象列表,并且您想要创建一个匹配多个名称之一的过滤器(假设您不想为每个名称创建一个过滤器条目),您可以这样做:
const createFilterDesc = (options) => ({
field: 'name',
value: new Set(options),
operator: (val, opts) => opts.has(val),
});
根据 the docs,FilterDescriptor
的 operator
属性可以是一个函数。
filterDescriptor.d.ts
/**
* A basic filter expression. Usually a part of [`CompositeFilterDescriptor`]({% slug api_kendo-data-query_compositefilterdescriptor %}).
*
* For more information, refer to the [`filterBy`]({% slug api_kendo-data-query_filterby %}) method.
*/
export interface FilterDescriptor {
/**
* The field of the data item to which the filter operator is applied.
*/
field?: string | Function;
/**
* The filter operator (comparison).
*
* The supported operators are:
* * `"eq"` (equal to)
* * `"neq"` (not equal to)
* * `"isnull"` (is equal to null)
* * `"isnotnull"` (is not equal to null)
* * `"lt"` (less than)
* * `"lte"` (less than or equal to)
* * `"gt"` (greater than)
* * `"gte"` (greater than or equal to)
*
* The following operators are supported for string fields only:
* * `"startswith"`
* * `"endswith"`
* * `"contains"`
* * `"doesnotcontain"`
* * `"isempty"`
* * `"isnotempty"`
*/
operator: string | Function;
/**
* The value to which the field is compared. Has to be of the same type as the field.
*/
value?: any;
/**
* Determines if the string comparison is case-insensitive.
*/
ignoreCase?: boolean;
}
我在互联网上找不到任何关于 FilterDescriptor.operator
的函数签名的信息。当然,因为 Kendo 不是开源的,我不能简单地检查他们的代码。
通过一些日志记录,我明白了。
export interface FilterDescriptor {
// ...
operator: string | ((fieledValue: any, filterValue: any) => boolean);
}
因此,如果您有一个带有名称的对象列表,并且您想要创建一个匹配多个名称之一的过滤器(假设您不想为每个名称创建一个过滤器条目),您可以这样做:
const createFilterDesc = (options) => ({
field: 'name',
value: new Set(options),
operator: (val, opts) => opts.has(val),
});