排序方法 :

sortBykey (ary, key) {
      return ary.sort(function (a, b) {
        let x = a[key]
        let y = b[key]
        return ((x < y) ? -1 : (x > y) ? 1 : 0)
      })
    }

将数组 进行排序前的处理:

 // 将增加 和 删除 进行排序处理
          that.sTableData.forEach(s => {
            if (s.colorType === 'add') { Object.assign(s, {colorSort: 1}) }
            if (s.colorType === undefined) { Object.assign(s, {colorSort: 2}) }
            if (s.colorType === 'delete') { Object.assign(s, {colorSort: 3}) }
          })
          that.sortBykey(that.sTableData, 'colorSort') // colorSort 为数组中对象的key
Logo

前往低代码交流专区

更多推荐