angular - 具有映射值的 Ng 自动完成过滤器列表功能
问题描述
我正在尝试像这样填充下拉列表:
this.service.loadProducts()
.pipe(
map(response => response.map(element => new Product(element)))
)
.subscribe(arr => this.products = arr);
是否有任何理由在 ng-autocomplete 过滤器列表功能中执行 item.constructor === 对象检查?
filterList() {
this.selectedIdx = -1;
this.initSearchHistory();
if (this.query != null && this.data) {
this.toHighlight = this.query;
this.filteredList = this.data.filter((/**
* @param {?} item
* @return {?}
*/
(item) => {
if (typeof item === 'string') {
// string logic, check equality of strings
return item.toLowerCase().indexOf(this.query.toLowerCase()) > -1;
}
else if (typeof item === 'object' && item.constructor === Object) {
// object logic, check property equality
return item[this.searchKeyword].toLowerCase().indexOf(this.query.toLowerCase()) > -1;
}
}));
}
else {
this.notFound = false;
}
}
由于该检查,过滤失败。有没有办法在 map 方法中不使用 return 语句来做到这一点?
解决方案
推荐阅读
- python - 循环运行从数量到数量的流程
- javascript - 通过 jQuery 修改 CSS 高度的意外行为
- html - 使用 Bootstrap 4 将版权页脚定位到 Angular / C# 应用程序的底部
- python - 在 matplotlib 中传递用于绘图的元组会在第 1 行引发“元组对象不可调用”错误。3
- graphql - 如何在graphql的嵌套查询中传递参数?
- django - 如何在我要编辑的实例中显示数据?
- here-api - 如何防止 HERE 航点图出现较大偏差?
- javascript - 如何使用 docx 从角度将图像添加到 Word 文档?
- formula - 如何在画面中创建分区十分位数?(某些组内的十分位数)
- alexa - Alexa APL Pager OnPageChanged 事件仅通过触摸触发