数组拍平和对象拍平(lodash)

trsfromData(data,chidlren) {
      const targetData = data;
      function flat(dataObj) {
        return reduce(dataObj, (result, item) => {
          result.push(item);
          if (item[chidlren]) {
            result = result.concat(flat(item[chidlren]));
          }
          return result;
        }, []);
      }
      return flat(targetData);
    },
  },
trsfromData(data,chidlren) {
      let flat=(data)=>reduce(data,(result,v)=>{
        result[v.paramCode]=v
        if(v[chidlren]){
          Object.assign(result,flat(v[chidlren]))
        }
       return result
      },{})
      return flat(this.items)
  },

你可能感兴趣的:(数组拍平和对象拍平(lodash))