0
我想在我的页面上有一个搜索过滤器。但是,它好像总是返回undefined。以下是我的手稿:Ionic 2:搜索过滤器返回undefined
filterItems(searchTerm) {
this.category.forEach((item) => {
return item.data.filter((data) =>{
data.title.toLowerCase().indexOf(searchTerm.toLowerCase()) > -1;
})
});
}
setFilteredItems() {
this.searchControl.valueChanges.debounceTime(500).subscribe(search => {
this.searching = false;
this.loadcategory = this.filterItems(this.searchTerm);
if (this.searchTerm == "") {
this.loadcategory = [];
this.searchresultcount = "0";
} else {
this.loadcategory;
console.log(this.loadcategory)
}
});
}
我console.log(this.loadcategory),但显然它返回未定义。我的代码中有没有出现错误的地方?任何帮助将非常感激。
您应该创建一个管道导致这就是管道的制造。你可以在这里查看一个例子https://github.com/VadimDez/ng2-filter-pipe/blob/master/src/ng2-filter.pipe.ts – misha130
如何在模板中使用searchTerm? –