toODataString方法 抛出错误 filterOperators(...)不是一个函数 Kendo Angular

问题描述 投票:1回答:1

我在Angular中使用了Kendo Jquery的Filter widget,为了将Filter Expression转换为oData Query,我使用了toODataQuery方法并将状态传递给它。为了将过滤器Expression转换为oData Query,我使用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.comeditangular-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-ui odata kendo-ui-angular2
1个回答
1
投票

我曾向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;
                }
            });
        }
  }
© www.soinside.com 2019 - 2024. All rights reserved.