您好,我想根据选中的复选框过滤我的数据。
我有 3 个复选框。
<input type="checkbox" name="shoes" value="shoes" class="storesCheckBox" />
<input type="checkbox" name="clothes" value="clothes" class="storesCheckBox" />
<input type="checkbox" name="sports" value="sports" class="storesCheckBox" />
我的商店数据是
// my stores
var stores = [
{
id: 1,
store: 'Store 1',
storeType: "shoes"
},
{
id: 2,
store: 'Store 2',
storeType: "clothes"
},
{
id: 3,
store: 'Store 3',
storeType: "sports"
},
{
id: 4,
store: 'Store 3',
storeSells: "shoes"
}
]
所以,如果我选中shoes复选框,我想根据 storeType 过滤数据shoes。所以我写了
var getStores = stores.filter(function (store) {
return store.storeType === 'shoes';
});
但是现在,如果我检查clothes并且shoes已经检查。我想过滤shoes + clothes数据。如果我取消选中,shoes我只想过滤衣服数据。它可以是任意数量的复选框,具体取决于商店类型。你能帮我解决这个问题吗?
喵喵时光机
UYOU
慕妹3242003
拉风的咖菲猫
随时随地看视频慕课网APP
相关分类