我正在嘗試構建一個自定義過濾器,該過濾器返回與輸入相匹配的項目。 它適用於簡單的數組,如['Apple', 'Banana', 'Cupple']
。 但不與對象的數組(我想用這個來過濾包含用戶信息的數組)在模板vue 2.0中的自定義過濾器不會返回任何內容
filterBy: function (arr, value) {
return arr.filter(function(item) {
item = item.toString();
return item.indexOf(value) > -1;
})
},
我
<input v-model="userInput" />
<h2> Customer: </h2>
<ul v-for="customer in filterBy(customers, userInput)">
<li>{{customer.name}}</li>
</ul>
編輯:這是什麼數據看起來像。
"data":[{"id":"9","name":"missy","phone":"21324234532"},
{"id":"3","name":"Mahama","phone":"345604542"}]
如何獲得與給定輸入相匹配的客戶?
請問你的對象數組是什麼樣子? – Saurabh
我已添加。我打算使用手機作爲搜索輸入,但返回客戶名稱。 –