1、遍历(forEach)

                this.fields.forEach(item=>{
                  if (item.spanFlag == true) {
                    this.setData(newValue, item.fieldName);
                  }
                })

 2、循环(filter)

      showColField(record,fields){
        return fields.filter(field=> this.showCol(record,field))
      },

3、排序(sort)

                treeData.sort((a,b)=>{
                    return a.indexId - b.indexId
                })

4、分组(groupBy)

function groupBy(arr, key) {
    let result = [];
    if (arr == null) {
        return null;
    }
    arr.forEach(item => {
        let find = result.filter(d=>d.groupName == item[key]);
        if (find.length > 0) {            
            find[0].groupData.push(item);
        } else {
            let list = [];
            list.push(item);
            result.push({"groupName": item[key], "groupData": list});
        }        
    });
    return result;
}

作到vue全局的方法

Array.prototype.groupBy = function(key) {
  return this.reduce((acc, cur) => {
    const groupKey = cur[key];
    if (!acc[groupKey]) {
      acc[groupKey] = [cur];
    } else {
      acc[groupKey].push(cur);
    }
    return acc;
  }, {});
};

Logo

前往低代码交流专区

更多推荐