【问题标题】:Filter data with array- vuejs 2使用array-vuejs 2过滤数据
【发布时间】:2018-02-09 02:01:12
【问题描述】:

我有一个数组对象,我想过滤那个数组。我已经知道如何使用计算属性按单个值过滤数据,

computed: {
    filteredValue() {
        return this.graphData.filter(data => data.YEAR === this.selectedYears)
    }
},

但我想按多个值/数组过滤数据。假设我有一个具有年份的数组对象:1901-2000。我只想过滤那些被选中的年份(如 1901、1902、1903)。任何人都可以帮助我。 TIA

【问题讨论】:

标签: vuejs2


【解决方案1】:

我认为您需要维护一个 selectedYears 数组。然后,像这样使用它。

computed: {
   filteredValue() {
      return this.graphData.filter(data => this.selectedYears.includes(data.YEAR);
  } 
}

【讨论】:

  • 感谢您的回复,我也刚弄明白了。
猜你喜欢
  • 2018-02-05
  • 1970-01-01
  • 2020-01-28
  • 1970-01-01
  • 1970-01-01
  • 2015-12-19
  • 1970-01-01
  • 2018-10-27
  • 2021-06-03
相关资源
最近更新 更多