Это мой код. Он содержит мой HTML и JS-код.
<script>
const toLower = text => {
return text.toString().toLowerCase()
}
const searchByState = (items, term) => {
if (term) {
return items.filter(item => toLower(item.state).includes(toLower(term)))
}
return items
}
const searchByCategory = (items, term) => {
if (term) {
return items.filter(item => toLower(item.category).includes(toLower(term)))
}
return items
}
export default {
name: 'TableSearch',
data: () => ({
search: null,
searchCategory:null,
searched: [],
users: [
{
name: "ABCD",
state: "Selangor",
category: "F&B"
},
{
name: "KLM",
state: "Penang",
category: "Entertainment"
},
{
name: "cvfd",
state: "Johor",
category: "H&B"
}
]
}),
methods: {
newUser () {
window.alert('Noop')
},
searchOnTable () {
this.searched = searchByState(this.users, this.search)
}
},
searchOnTable () {
this.searched = searchByCategory(this.users, this.searchCategory)
},
created () {
this.searched = this.users
}
}
</script>
<template>
<div>
<md-table v-model="searched" md-sort="name" md-sort-order="asc" md-card md-fixed-header>
<md-table-toolbar>
<div class="md-toolbar-section-start">
<h1 class="md-title">Users</h1>
</div>
<md-field md-clearable class="md-toolbar-section-end">
<label for="state">State</label>
<md-select placeholder="Search by State..." v-model="search" @input="searchOnTable" multiple>
<md-option value="penang">Penang</md-option>
<md-option value="selangor">Selangor</md-option>
<md-option value="johor">Johor</md-option>
<md-option value="sabah">Sabah</md-option>
<md-option value="sarawak">Sarawak</md-option>
<md-option value="perak">Perak</md-option>
<md-option value="kedah">Kedah</md-option>
<md-option value="pahang">Pahang</md-option>
<md-option value="kelantan">Kelantan</md-option>
<md-option value="terengganu">Terrenganu</md-option>
<md-option value="melaka">Melaka</md-option>
<md-option value="negeri sembilan">Negeri Sembilan</md-option>
<md-option value="perlis">Perlis</md-option>
<md-option value="kuala lumpur">Kuala Lumpur</md-option>
</md-select>
</md-field>
<md-field md-clearable class="md-toolbar-section-end">
<label for="category">Category</label>
<md-select placeholder="Search by Category..." v-model="searchCategory" @input="searchOnTable" multiple>
<md-option value="penang">Penang</md-option>
<md-option value="f&b">F&B</md-option>
<md-option value="h&b">H&B</md-option>
<md-option value="entertainment">Entertainment</md-option>
<md-option value="services">Services</md-option>
</md-select>
</md-field>
</md-table-toolbar>
<md-table-empty-state
md-label="No users found"
:md-description="`No user found for this '${search}' and '${searchCategory}' query. Try a different state and category`">
</md-table-empty-state>
<md-table-row slot="md-table-row" slot-scope="{ item }">
<md-table-cell md-label="Merchant">{{ item.name }}</md-table-cell>
<md-table-cell md-label="State">{{ item.state }}</md-table-cell>
<md-table-cell md-label="Category">{{ item.category }}</md-table-cell>
</md-table-row>
</md-table>
</div>
</template>
Я использую Vue MD и хочу иметь возможность выбрать несколько состояний и категорий одновременно. Прямо сейчас я могу выбрать только одно состояние, и оно отфильтрует его. Я новичок в Vue MD. Пожалуйста, помогите, если кто-нибудь знает, как решить проблему. Заранее спасибо.