toODataString 方法抛出错误 filterOperators(...) 不是函数 Kendo Angular
toODataString Method Throwing error filterOperators(...) is not a function Kendo Angular
我正在为 Angular 使用 Kendo UI 的过滤器小部件。为了将过滤器表达式转换为 oData 查询,我使用 toODataQuery 方法并将状态传递给它。
添加组时我得到
filterOperators(...) is not a function
at odata-filtering.operators.js:69
at funcs.js:4
at odata-filtering.operators.js:70
at Array.map (<anonymous>)
我为此创建了 stackblitz:https://stackblitz.com/edit/angular-ivy-gny5pv?file=src%2Fapp%2Fapp.component.ts
我能够重现错误,但错误是不同的。
我做错了什么...??
app.component.ts:
import { Component, OnInit, ElementRef, ViewChild, Output, Input, EventEmitter } from '@angular/core';
import { CompositeFilterDescriptor, FilterDescriptor, State, toODataString, normalizeFilters } from '@progress/kendo-data-query';
declare var kendo: any;
@Component({
selector: 'my-app',
template: `
<div #positionFilter></div>
`
})
export class AppComponent implements OnInit {
@ViewChild('positionFilter',{static: true}) positionFilter: ElementRef;
public filterExpression: CompositeFilterDescriptor;
public state: State = {
skip: 0,
take: 5,
// Initial filter descriptor
filter: null
};
ngOnInit() {
this.loadFilter(this.positionFilter.nativeElement, this.filterExpression);
}
public loadFilter(filterContainer, expressionVal) {
kendo.jQuery(filterContainer).kendoFilter({
dataSource: [],
//applyButton: false,
expressionPreview: true,
expression: expressionVal,
change: this.onChangeFieldDropDownEvent.bind(this),
fields: [
{ name: "ProductName",type: "string", label: "String" },
{ name: "CategoryID", type: "number", label: "Number"},
{ name: "UnitPrice", type: "boolean", label: "boolean"},
{ name: "UnitsInStock", type: "date", label: "Date" }
]
});
}
onChangeFieldDropDownEvent(e) {
console.log('Filter Expression--', e.expression);
this.addSearch();
this.filterExpression = e.expression;//.filters;
this.updateState(this.filterExpression);
let serializedFilterValue = this.serializeFilter(this.state);
console.log('serializedFilterValue----', serializedFilterValue)
}
public updateState(filter) {
this.state.filter = filter;
}
private serializeFilter(state: State): string {
return toODataString(state);
}
public addSearch() {
let container = this.positionFilter.nativeElement;
kendo.jQuery(container).find(".k-filter-field select.k-filter-dropdown").each(function (i, x) {
kendo.jQuery(x).data("kendoDropDownList").setOptions({ filter: "contains" });
});
}
}
我向 Kendo 团队提出了这个问题。
这是他们的建议:
出现此问题是因为 toODataString 无法序列化空过滤器对象。一种可能的解决方案是在序列化参数之前删除所有空过滤器。
例如
private serializeFilter(state: State): string {
removeEmptyFilters(state.filter)
return toODataString(state);
}
function removeEmptyFilters(expression){
var that = this;
if (expression.filters) {
expression.filters = kendo.jQuery.grep(expression.filters, function(filter) {
removeEmptyFilters(filter);
if (filter.filters) {
return filter.filters.length;
} else {
return filter.value;
}
});
}
}
我正在为 Angular 使用 Kendo UI 的过滤器小部件。为了将过滤器表达式转换为 oData 查询,我使用 toODataQuery 方法并将状态传递给它。
添加组时我得到
filterOperators(...) is not a function
at odata-filtering.operators.js:69
at funcs.js:4
at odata-filtering.operators.js:70
at Array.map (<anonymous>)
我为此创建了 stackblitz:https://stackblitz.com/edit/angular-ivy-gny5pv?file=src%2Fapp%2Fapp.component.ts
我能够重现错误,但错误是不同的。 我做错了什么...??
app.component.ts:
import { Component, OnInit, ElementRef, ViewChild, Output, Input, EventEmitter } from '@angular/core';
import { CompositeFilterDescriptor, FilterDescriptor, State, toODataString, normalizeFilters } from '@progress/kendo-data-query';
declare var kendo: any;
@Component({
selector: 'my-app',
template: `
<div #positionFilter></div>
`
})
export class AppComponent implements OnInit {
@ViewChild('positionFilter',{static: true}) positionFilter: ElementRef;
public filterExpression: CompositeFilterDescriptor;
public state: State = {
skip: 0,
take: 5,
// Initial filter descriptor
filter: null
};
ngOnInit() {
this.loadFilter(this.positionFilter.nativeElement, this.filterExpression);
}
public loadFilter(filterContainer, expressionVal) {
kendo.jQuery(filterContainer).kendoFilter({
dataSource: [],
//applyButton: false,
expressionPreview: true,
expression: expressionVal,
change: this.onChangeFieldDropDownEvent.bind(this),
fields: [
{ name: "ProductName",type: "string", label: "String" },
{ name: "CategoryID", type: "number", label: "Number"},
{ name: "UnitPrice", type: "boolean", label: "boolean"},
{ name: "UnitsInStock", type: "date", label: "Date" }
]
});
}
onChangeFieldDropDownEvent(e) {
console.log('Filter Expression--', e.expression);
this.addSearch();
this.filterExpression = e.expression;//.filters;
this.updateState(this.filterExpression);
let serializedFilterValue = this.serializeFilter(this.state);
console.log('serializedFilterValue----', serializedFilterValue)
}
public updateState(filter) {
this.state.filter = filter;
}
private serializeFilter(state: State): string {
return toODataString(state);
}
public addSearch() {
let container = this.positionFilter.nativeElement;
kendo.jQuery(container).find(".k-filter-field select.k-filter-dropdown").each(function (i, x) {
kendo.jQuery(x).data("kendoDropDownList").setOptions({ filter: "contains" });
});
}
}
我向 Kendo 团队提出了这个问题。
这是他们的建议:
出现此问题是因为 toODataString 无法序列化空过滤器对象。一种可能的解决方案是在序列化参数之前删除所有空过滤器。 例如
private serializeFilter(state: State): string {
removeEmptyFilters(state.filter)
return toODataString(state);
}
function removeEmptyFilters(expression){
var that = this;
if (expression.filters) {
expression.filters = kendo.jQuery.grep(expression.filters, function(filter) {
removeEmptyFilters(filter);
if (filter.filters) {
return filter.filters.length;
} else {
return filter.value;
}
});
}
}