多维数组转一维数组(扁平化)

getscoreInfo(scopeId) {
      this.spinningLoading = true
      scoreInfo({ scopeId: '1497142253250936832' })
        .then((res) => {
          this.spinningLoading = false
          if (res.success) {
            const { baseInfo, object, scoreProcessList } = res.data
            this.planName = baseInfo.title
            this.period = `${baseInfo.startDate} ~ ${baseInfo.endDate}`
            this.resultData = res.data
            //多维数组转为一维数组
            let responseData = res.data.indicatorDimensionList
            let arr = []
            responseData.map((responseDataItem, index2) => {
              let type = true
              const len1 = responseDataItem.indicatorResultList.length
              responseDataItem.indicatorResultList.map((timeDataItem) => {
                const len2 = timeDataItem.scoreList.length
                timeDataItem.scoreList.map((scoreListItem, index) => {
                  arr = [
                    ...arr,
                    {
                      zhibiao: timeDataItem.title,
                      description: timeDataItem.description,
                      standard: timeDataItem.standard,
                      title: `${responseDataItem.title}(${responseDataItem.weight}%)`,
                      weight: `${timeDataItem.weight}%`,
                      name: scoreListItem.collector.name,
                      score: scoreListItem.score,
                      comment: scoreListItem.comment,
                      totalScore: timeDataItem.totalScore,
                      id: responseDataItem.id,
                      titleSpan: Number(`${type ? len2 * len1 : 0}`),
                      twoSpan: index === 0 ? len2 : 0,
                    },
                  ]
                  type = false
                  return arr
                })
              })
            })
            this.data = arr
          }
        })
        .finally(() => {
          this.spinningLoading = false
        })
    },

你可能感兴趣的:(vue,vue.js)