zoukankan      html  css  js  c++  java
  • es6条件查询筛选数据

    引用场景如下,列表查询时需要用到前端查询

     具体实现方法如下

    前面定义的变量是查询条件,this.allData表示被筛选的数据,filteData是查询结果

        queryData () {
          let officerType = this.search.officerType
          let officerName = this.search.officerName
          let position = this.search.position
          let filterData = this.allData.filter( item => {
            let isOfficerType = officerType.length > 0 && item.officerType.indexOf(officerType) === -1 ? false : true
            let isOfficerName = officerName.length > 0 && item.officerName.indexOf(officerName) === -1 ? false : true
            let isPosition = position.length > 0 && item.position.indexOf(position) === -1 ? false : true
            //返回筛选条件
            return isOfficerType && isOfficerName && isPosition
          })
          this.officerData = filterData
        },

    因为有多个地方需要用到前端查询,我们可以进行封装

    在util.js里面

    // 前端查询
    let queryData = function (query, allData) {
      //数据格式
      // let query = [
      //   {
      //     key: 'officerType',
      //     value: this.search.officerType
      //   },{
      //     key: 'officerName',
      //     value: this.search.officerName
      //   }
      // ]
      let filterData = allData.filter( item => {
        return query.every( innerItem => {
          return innerItem.value.length > 0 && item[innerItem.key].indexOf(innerItem.value) === -1 ? false : true 
        })
      })
      return filterData
    }

    组件里面调用

        // 前端查询列表
     queryData () {
         // 查询参数
          let query = [
            {
              key: 'teamType',
              value: this.search.teamType
            },{
              key: 'teamName',
              value: this.search.teamName
            }
          ]
          let allData = this.allData  // 被筛选数据
          this.teamData = this.$util.queryData(query, allData)
    }
  • 相关阅读:
    java 分解质因数
    Unix 文件系统读写时权限校验
    find 命令实战巧用
    Linq分组功能
    三种查看SqlServer中数据物理pge页的方法
    一个高度压缩的bit位图字典的实现
    windbg 命令 gchandles
    ManualResetEvent和AutoResetEvent的区别实例
    一些汇编指令(基于8086)
    windbg sos版本不匹配问题解决
  • 原文地址:https://www.cnblogs.com/qdlhj/p/12371269.html
Copyright © 2011-2022 走看看