Arrays 如何按ID的数据分组(映射)?

Arrays 如何按ID的数据分组(映射)?,arrays,vue.js,vuejs2,Arrays,Vue.js,Vuejs2,如何按客户ID对数据进行分组 它不起作用,我尝试不同的方式,但我认为我不理解这种结构 这是我的代码: function CustomerGroup() { this.$http.post(auth.API_URL + 'api/ProblemsSupports/ProblemsList', null, { headers: { 'Authorization': 'Bearer ' + auth.getAuthHeader() } }).then((response

如何按
客户ID
对数据进行分组

它不起作用,我尝试不同的方式,但我认为我不理解这种结构

这是我的代码:

function CustomerGroup() {
this.$http.post(auth.API_URL + 'api/ProblemsSupports/ProblemsList', null, {
    headers: {
        'Authorization': 'Bearer ' + auth.getAuthHeader()
    }
}).then((response) => {
    this.problemitems = response.body
    const map = this.problemitems.map(e => (map[e.CustomerID] = map[e.CustomerID]))
    return map
    this.progress = false
}, (response) => {
    if (response.status === 0) {
        this.text1 = ' !!!'
        this.snackbar = true
        this.progress = false
    } else {
        this.text1 = '!!!!!!'
        this.snackbar = true
        this.progress = false
    }
})
}

例如,您可以使用此功能:

groupBy (list, keyValue) {
const map = new Map()
list.forEach((item) => {
  const key = item[keyValue]
  const collection = map.get(key)
  if (!collection) {
    map.set(key, [item])
  } else {
    collection.push(item)
  }
})
return Array.from(map.values())  
}
那就叫它吧

const map = groupBy(this.problemitems, 'CustomerID')

您可以在Vue方法中使用函数,然后不要忘记
这个

您想要实现什么?到底发生了什么?我有不同的问题。我需要为customerID对这些问题进行分组,例如-X公司-40个问题-Y公司-50个问题可能重复的