filter的用法与使用场景:筛选数据

//this.allCollectorList:后台给定的所有可供选择数据
//this.collectorData:目前已经存在选中列表中的数据



//目前已经存在选中列表中的数据id
getSelIdList() {
   let eIdList = []
   this.collectorData.forEach(row => {
      eIdList.push(row.id)
   })
   return eIdList
},


//在中的数据列表中删除目前已经存在的数据,就是余下全部数据
filterCollec() {
  let eIdList = this.getSelIdList()
  this.allCollectorData = this.allCollectorList.filter(row => {
    return eIdList.indexOf(row.id) == -1
  })
},

 1、使用场景:筛选数据后台给了多选框的数据列表,前端通过选中和反选,传值给后台多选框的id,记录实际的XX类型

typeList = [
    {
        "id": "1",
        "code": "1",
        "name": "通讯",
        "type": 1,
        "status": 1,
        "remark": null,
        "pid": null,
        "ext1": "",
        "ext2": null,
        "ext3": null,
        "sort": 1
    },
    {
        "id": "4",
        "code": "4",
        "name": "微型器",
        "type": 1,
        "status": 1,
        "remark": null,
        "pid": null,
        "ext1": "",
        "ext2": null,
        "ext3": null,
        "sort": 3
    },
    {
        "id": "28",
        "code": "5",
        "name": "多功能表",
        "type": 1,
        "status": 1,
        "remark": null,
        "pid": null,
        "ext1": "",
        "ext2": null,
        "ext3": null,
        "sort": 4
    },
    {
        "id": "612",
        "code": "55",
        "name": "单电表",
        "type": 1,
        "status": 1,
        "remark": null,
        "pid": null,
        "ext1": "",
        "ext2": null,
        "ext3": null,
        "sort": 5
    },
    {
        "id": "613",
        "code": "56",
        "name": "三相表",
        "type": 1,
        "status": 1,
        "remark": null,
        "pid": null,
        "ext1": "",
        "ext2": null,
        "ext3": null,
        "sort": 6
    }
]

<el-form-item label="设备类型:">
            <el-checkbox-group v-model="formData1.airSwitchTypeAry">
              <el-checkbox :key="i" v-for="(item, i) in typeList" :label="item.code">{{ item.name }}</el-checkbox>
            </el-checkbox-group>
          </el-form-item>





watch: {
      'formData.airSwitchTypeAry': function (val, oldval) {
        if (val.length > 0) {
          let ids = this.typeList
            .filter((it) => val.indexOf(it.code) > -1)
            .map((it) => it.id)
          console.log(111, ids)
          this.modelList = this.allModelList.filter(
            (it) => ids.indexOf(it.pid) > -1
          )
        } else {
          this.modelList = this.allModelList
        }
      }
    }
2、使用场景:两个table列表中的数据实现穿梭框功能(筛选数据实现两个表格中的数据相互交换)

 

  • 7
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值