vue.js - Vue在getter中链接多个过滤器
问题描述
在 Getter 上,我需要过滤一个数组并返回符合 2 个条件的值。我需要返回没有 item_category_location 等于当前位置或根本没有 item_category_locations 的 item_categories。
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个过滤器工作正常。如何链接它们以创建新数组?
解决方案
你可以这样做:
return [...otherLocations, ...noLocations]
推荐阅读
- hyperlink - IBM Watson Assistant:如何将作为锚链接的超链接包含在响应中?
- java - 返回ListView时如何保留最后选择的位置?
- linux - 珊瑚开发板 hdmi arc 输入/输出错误
- shell - 解释 sed 命令: df -P 。| sed -n '$s/[[:blank:]].*//p'
- javascript - 如何通过 javascript/Angularjs 在局域网中获取 IP
- excel - 访问形状的字符对象
- apache - 网站的一个文件夹中的空白页而不是“/的索引”
- python - 气流可以与编译的python dag一起使用吗?
- javascript - 即使在创建“静态”目录并更改和更改之后也无法加载 CSS 和 Javascript