【发布时间】:2019-10-30 07:17:39
【问题描述】:
我做了两个 Vue.js 多复选框过滤器的例子:“工作”和“游戏”。
“工作”:https://jsfiddle.net/ostapenko25/cw7kyp83/
《游戏》:https://jsfiddle.net/ostapenko25/bu7hcvqg/
//“Jobs”
computed: {
filteredJobs() {
return this.jobs.filter(({ id, userId }) => {
return (
(this.checkedUserIds.length === 0 ||
this.checkedUserIds.includes(userId)) &&
(this.checkedIds.length === 0 || this.checkedIds.includes(id))
);
});
}
}
//“Games”
computed: {
filteredGames() {
return this.games.filter(({ game_id, season }) => {
return (
(this.checkedseasons.length === 0 ||
this.checkedseasons.includes(season)) &&
(this.checkedgame_ids.length === 0 || this.checkedgame_ids.includes(game_id))
);
});
}
}
除了 JSON 数据以及键和属性的名称之外,它们完全相同。但是第一个示例有效,而第二个示例无效:当我尝试使用复选框时,游戏列表变为空。请帮我找出是我在“游戏”示例中的错误。
【问题讨论】: