[英]Vue js searching array
我正在嘗試在數組中搜索json對象上的查詢字符串。 返回的字段是過濾結果的數組。 當前,列表返回的是名稱字段,而不是數字字段。
computed: {
search: function () {
let self = this
let filtered = []
filtered = self.jcontacts.filter(function(contact){
return contact.firstname.toLowerCase().indexOf(self.query.toLowerCase())>=0 ||
contact.lastname.toLowerCase().indexOf(self.query.toLowerCase())>=0;
contact.email.toLowerCase().indexOf(self.query.toLowerCase()) >=0 ||
contact.phonenumber.toLowerCase().indexOf(self.query.toLowerCase()) >=0;
}
);
return this.contacts = filtered
}
},
}
搜索方法中的過濾方法未顯示該數字。 json的示例如下:
[{“ id”:1,“ phoneNumber”:[“ 3908902”],“ email”:[“ jamie@fox.com”],“ firstname”:“ Jamie”,“ lastname”:“ Fox”}]
phoneNumber != phonenumber
.includes()
函數) self.query.toLowerCase()
存儲為變量或其他計算的屬性 這是一個錯字 。 簽出字段phoneNumber被過濾為電話號碼。
它是一個數組,因此您可以按以下方式進行操作:
contact.phoneNumber.forEach( number => {
if(number.toLowerCase().indexOf(self.query.toLowerCase()) >=0)
return true;
});
我認為類似地,您也可以將其記入電子郵件,因為它也是一個數組。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.