xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

Object to Array

Object to Array


    objectToArray(obj = {}, title = `标题`){
      let datas = [];
      if(Object.keys(obj).length) {
        datas = [...Object.entries(obj)].map((item, i) => {
          return {
            key: item[0],
            value: item[1],
          };
        });
      }
      return {
        title,
        datas,
      };
    },
    detailTableShaper(json = []){
      const {
        // productName,
        productInfo,
        productTypeInfo,
        productSortInfo,
        productTagInfo,
      } = json;
      const result = [];
      result.push(this.objectToArray(productInfo, "商品信息"));
      result.push(this.objectToArray(productTypeInfo, "类型区分"));
      result.push(this.objectToArray(productSortInfo, "排序条件"));
      result.push(this.objectToArray(productTagInfo, "销售标签"));
      return result;
    },


posted @ 2020-03-17 23:37  xgqfrms  阅读(186)  评论(1编辑  收藏  举报