Vue用数组过滤项目列表

时间:2021-06-18 06:31:17

标签: vue.js

我有一系列可以像这样过滤的项目。

return this.items.filter((item) => {
    return !this.requestType || (item.requestsubtypeid === this.requestType && item.status === this.status);
})

this.requestType 只是一个数字时,这非常有效。但是现在它可以是一个数组,所以我的问题是,当它是一个数组时如何过滤? 我应该使用 for 循环还是有更好的方法?

1 个答案:

答案 0 :(得分:0)

如果 requestType 始终是一个数组,您可以使用以下内容:

return this.items.filter((item) => {
    return !this.requestType || (this.requestType.includes(item.requestsubtypeid) && item.status === this.status);
})