es5中的去重复数据以及el-table默认选中

2018-09-13  本文已影响0人  简小咖

去重复数据

初始化有一组数据,添加第二组数据时要判断数据是否存在,如果存在不插入,不存在的话插入这条新数据

image.png
   this.list.forEach(item => {
        if (item.isSelect) {
          var hasItem = this.updateList.some(k => {
            return k.id === item.id
          })
          hasItem || this.updateList.push(item)
        }
      })
const list = response.data
let hash = {};
let config =this.updateList
list.forEach(item => {
        iconfig.push(item)
 })
const newArr = config.reduceRight((item, next) => {
    hash[next.id] ? '' : hash[next.id] = true && item.push(next);
    return item
}, []);

el-table默认选中

官网的方法

    toggleSelection(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row, true)
         //this.$refs.multipleTable.toggleRowSelection(row)
        })
      } else {
        this.$refs.multipleTable.clearSelection()
      }
    },

初始化的时候调用方法即可,vue中必须用.$nextTick可以实现,不然可能不起作用

   this.$nextTick(function() {
          this.toggleSelection(this.employeedetail.shops)
        })
上一篇下一篇

猜你喜欢

热点阅读