【发布时间】:2018-02-03 11:02:49
【问题描述】:
我正在使用 Ionic 3.x。
我编写了一个基本的聊天应用程序,并希望能够过滤聊天中的单词。
我刚刚尝试在我的应用程序中实现一个搜索栏。我像这样修改了 HTML 文件:
<ion-searchbar (ionInput)="getItems($event)"></ion-searchbar>
<ion-item *ngFor="let chat of tempChats">
在 HTML 文件中,我有一个对象数组:
chats: Object[]=[];
tempChats: Object[]=[];
我后来填写了带有消息和标题的聊天。像这样:
this.chats.push({author: 'Jim',message: 'Hi!'});
然后我写了一个initializeChats函数和一个getItems函数:
initializeChats(){
this.tempChats=this.chats;
}
getItems(){
this.initializeChats();
let val = ev.target.value;
if (val && val.trim() != '') {
this.tempChats = this.tempChats.filter((chat) => {
return (chat.message.toLowerCase().indexOf(val.toLowerCase()) > -1);
})
}
}
不幸的是,这给出了错误: “对象”类型上不存在属性“消息”。
有人知道如何解决这个问题吗?
非常感谢您!
编辑: 做类似的事情
for(chat of chats){
alert(chat.name);
}
有效。
【问题讨论】:
标签: angular typescript filter ionic2 ionic3