• js auto expand array All In One


    js auto expand array All In One

    rows 自动扩展

    
    const rows = [
      {
          "name": "总计",
          "ins_num_10k": 0,
          "natural_ins_num_ratio": null,
          "cost_amount_10k": 96058.5732011944,
          "allpay_amount_10k": 0,
          "cpi": null,
          "roi_7": 0,
          "mau": 0,
          "_meta": {
              "ins_num_10k_trend": -1,
              "natural_ins_num_ratio_trend": null,
              "cost_amount_10k_trend": 1.2952897963,
              "allpay_amount_10k_trend": -1,
              "cpi_trend": null,
              "roi_7_trend": -1,
              "mau_trend": -1,
          }
      },
      {
          "name": "其他",
          "ins_num_10k": 0,
          "natural_ins_num_ratio": null,
          "cost_amount_10k": 0.00294292,
          "allpay_amount_10k": 0,
          "cpi": null,
          "roi_7": 0,
          "mau": 0,
          "_meta": {
              "ins_num_10k_trend": -1,
              "natural_ins_num_ratio_trend": null,
              "cost_amount_10k_trend": null,
              "allpay_amount_10k_trend": -1,
              "cpi_trend": null,
              "roi_7_trend": null,
              "mau_trend": -1,
          }
      },
    ];
    
    const autoExpandRows = (arr = [], name = 'row_name') => {
      const result = [];
      for (const obj of arr) {
        const newObj = {
          [name]: `${obj[name]}趋势`,
          // _meta: obj._meta,
          // _meta: {},
        };
        for (const key in obj._meta) {
          const newKey = key.replace(/_trend/, '');
          newObj[newKey] = obj._meta[key];
        }
        result.push(obj);
        result.push(newObj);
      }
      return result;
    };
    
    const test = autoExpandRows(rows);
    
    console.log('test', test);
    
    

    refs



    ©xgqfrms 2012-2020

    www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

    原创文章,版权所有©️xgqfrms, 禁止转载 ️,侵权必究⚠️!


    xgqfrms
  • 相关阅读:
    代码艺术 CountDownTimer
    java 正则
    What are the top 10 things that we should be informed about in life
    java 闭包与回调
    Hive记录-单机impala配置
    Hbase记录-Hbase介绍
    Hbase记录-Hbase其他工具
    Hbase记录-Hbase shell使用命令
    Hbase记录-Hbase Web管理工具
    CM记录-Hadoop运维管理
  • 原文地址:https://www.cnblogs.com/xgqfrms/p/15806003.html
Copyright © 2020-2023  润新知