1
次の計算された関数を持つので、検索入力フィールドに基づいて住宅をフィルタリングします。これは機能します。Vue計算された順序付きフィルタ
computed: {
filtered: function() {
var self = this;
let searchTerm = (this.search || "").toLowerCase()
if(this.houses) {
return this.houses.filter(function(item) {
let city = (item.city || "").toLowerCase()
let street = (item.street || "").toLowerCase()
return city.indexOf(searchTerm) > -1 || street.indexOf(searchTerm) > -1;
})
}
}
}
しかし、都市やストリートでも注文を実装する方法は? ascとdescの両方。
これはテーブルです:
<input type="search" v-model="search" placeholder="Search for City OR Street" />
<table>
<thead>
<tr>
<th @click="sortByStreet()">Street</th>
<th @click="sortByCity()">City</th>
</tr>
</thead>
<tbody>
<tr v-for="house in filtered">
<td>{{ house.street }}</td>
<td>{{ house.city }}</td>
</tr>
</tbody>
</table>
機能sortByStreet()
とsortByCity()
でそれを修正する方法は?フィルタと組み合わせる。
それはVue1が、NOG Vue2でいるようでした。それとも、あなたは模範を持っていますか? – user1469734
私はスニペットの例を追加しました。 –
素晴らしい!しかし、私はをもう使えません。両方の世界をマージすることについてのこの問題。そしてそれはただの唯一のものです。 – user1469734