首页 > 解决方案 > json数组离子3的搜索栏

问题描述

我正在使用 ionic 3 构建市场应用程序,我的列表项之一是“产品”

我的“产品页面”通过 HTTP 发布请求从 JSON 数组中获取项目,而不是条目数据

postProducts(type){
return this.http.get('URL').map(res => res.json()); 
}

我想建立一个搜索栏来按名称过滤我的产品

有什么帮助吗?

标签: angularcordovaionic-frameworkionic3

解决方案


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: "العروض الخــاصه"} 等等..


推荐阅读