【发布时间】:2020-01-06 09:21:42
【问题描述】:
在 Getter 上,我需要过滤一个数组并返回符合 2 个条件的值。 我需要返回 item_categories 的 item_category_location 不等于当前位置或根本没有 item_category_locations。
unaddedItemCategories(state, getters, rootState) {
let otherLocations = state.item_categories
.filter((item_category) =>
item_category.item_category_locations.some((item_category_location) => item_category_location.location_id !== rootState.currentLocation.id))
let noLocations = state.item_categories
.filter(item_category => item_category.item_category_locations.length == 0)
return otherLocations, noLocations
},
2 个过滤器工作正常。如何链接它们以创建新数组?
【问题讨论】:
-
为什么在退货声明中使用comma?
-
return 语句其实没什么意义,只是显示我想返回什么
-
如果您只是使用单个
filter和逻辑 OR||而不是过滤两次,这不是更清楚吗?如果也是迭代次数的一半。 -
是的,但我无法正确添加 || 的语法在其他位置。但肯定会更好。如果您可以在答案中显示它,我会接受