【发布时间】:2019-05-22 02:00:58
【问题描述】:
我想使用 PrimeNG 自动完成组件,但它没有按预期工作。如果您在输入字段中键入内容,则会执行 completeMethod,但不会显示结果。我首先测试了 completeMethod,它工作正常并正确过滤了数组,但是该组件没有显示带有我的值的建议列表,而是一直显示加载微调器。键入其他内容后,按任何其他键或单击其他位置会显示结果,但加载微调器仍然存在。
我已经搜索了解决方案,但没有发现对我的问题有用。我读到下拉点击有一些常见的类似问题,所以我尝试应用这些修复,但它对我也没有帮助。
拥有自动完成功能的组件,其 ChangeDetectionStrategy 设置在 OnPush 上
这是我的代码:
组件:
<p-autoComplete
[formControlName]="formName"
[suggestions]="options"
(completeMethod)="filterMethod($event)"
[dropdown]="true"
field="label"
[multiple]="true"
[forceSelection]="true"
[minLength]="3"
(onDropdownClick)="handleDropdownClick($event)"
></p-autoComplete>
过滤方法:
filterMethod(event: { query: string; originalEvent: any }) {
this.service
.getSelectItemsByService(this.id)
.subscribe(options => {
this.options = this.filter(event.query, options).slice();
});
}
private filter(query: string, options: SelectItem[]): SelectItem[] {
return query
? options.filter(value =>
value.label
.toLowerCase()
.trim()
.includes(query.toLowerCase().trim())
)
: options;
}
提前谢谢你!
【问题讨论】:
标签: javascript angular primeng