kendo-ui - @progress/kendo-data-query FilterDescriptor 算子函数签名
问题描述
根据docs,FilterDescriptor
的operator
道具可以是一个函数。
过滤器描述符.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),
});
推荐阅读
- lua - 有没有办法让 lua 脚本不那么滞后?
- c++ - 我在循环函数时遇到问题
- python - 街机 python 库的字体名称是什么?
- ios - 在项目和共享扩展之间共享数据
- c# - 在 C# 中,当我想将它从我的控制器移动到存储库文件时,我应该如何更改方法语法?
- c# - 如何编码为 png 网络摄像头纹理?
- c++ - 创建指向对象的指针时调用对象的不相关方法
- html - 如何在 VBA 中激活单击此超链接?
- printf - Z Shell:输入别名内容与调用别名本身产生不同的输出
- c# - 当 IDENTITY_INSERT 设置为 OFF 时,无法在“DentalProcedures”中插入标识列的显式值。EF代码优先