【发布时间】:2019-12-26 22:03:56
【问题描述】:
我想将过滤器应用于剑道 ui 下拉列表。 Here already provided the example
但是我的数据源是一个字符串数组,而不是像这样的数组
public data: Array<{ text: string, value: number }>;
我的数据是
public data: string[] = ['Apple', 'Orange', 'Banana'];
所以我修改了链接中的代码
import { Component, ViewChild } from '@angular/core';
@Component({
selector: 'my-app',
template: `
<kendo-dropdownlist
#list
[data]="data"
[filterable]="true"
>
</kendo-dropdownlist>
})
export class AppComponent {
@ViewChild("list") list;
public source: Array<string> = ['Apple', 'Orange', 'Banana'];
public data: Array<string>;
constructor() {
this.data = this.source.slice();
}
ngAfterViewInit() {
// need code here
.subscribe(x => {
this.data = x;
this.list.loading = false;
});
}
}
我想要的是 ngAfterViewInit() 里面的代码,我使用 angular 5 和 rxjs 5.5。它似乎无法与代码一起使用。
this.list.filterChange.asObservable().pipe(
switchMap(value => from([this.source]).pipe(
tap(() => this.list.loading = true),
delay(1000),
map((data) => data.filter(contains(value)))
))
)
【问题讨论】:
-
你没有效仿他们;为什么要从 HTML 中的
kendo-dropdownlist中删除textField和valueField?这些字段是必需的,我很确定。您还需要export class AppComponent implements AfterViewInit和import { AfterViewInit } from '@angular/core';才能运行该函数。 -
@xinthose,不这么认为。如果您查看example--Basic Usage。他们使用
public listItems: Array<string> = [ 'Baseball', 'Basketball', 'Cricket', 'Field Hockey', 'Football', 'Table Tennis', 'Tennis', 'Volleyball' ];
标签: angular kendo-ui angular5 kendo-ui-angular2