angular - json数组离子3的搜索栏
问题描述
我正在使用 ionic 3 构建市场应用程序,我的列表项之一是“产品”
我的“产品页面”通过 HTTP 发布请求从 JSON 数组中获取项目,而不是条目数据
postProducts(type){
return this.http.get('URL').map(res => res.json());
}
我想建立一个搜索栏来按名称过滤我的产品
有什么帮助吗?
解决方案
allrecs = [];
postProducts.subscript((response)=>{
this.allrecs.push(response);
}, (error)=>{
console.log("error")
})
filterRecs(searchTerm){
return this.allrecs.filter((rec) => {
return rec.name.toLowerCase().indexOf(searchTerm.toLowerCase()) > -1;
});
}
希望您的记录像:{id:40,名称:“كنور خلطة الكبسه”,描述:“2 قطعه”,价格:“2750”,类型:“العروض الخــاصه”},{id:40,名称:“كنور خلطة الكبس ", desc: "2 قطعه", price: "2750", type: "العروض الخــاصه"} 等等..
推荐阅读
- python - 将包含嵌套列表列表的字典转换为 df
- sql - 如何在没有找到行的删除后有条件地更新/插入?
- python - Python多线程:SystemError:内部例程的空参数
- c# - 使用 Prism 设置对话框的尺寸和位置时出现问题
- firebase - FlutterFire 更新 Array 而不是替换它
- mysql - 按列分组并选择具有多个最小值的行中的所有字段
- flutter - 我如何从类扩展 ChangeNotifier 中获取价值
- google-chrome-extension - 使用 chrome 扩展 v3 覆盖 navigator.useragent
- drools - 如何自动将类导入规则文件?
- android - 当我在模拟器上运行我的代码时出现 ListViewBuilder 问题。它显示“底部溢出 167 像素”