test.js 1.99 KB
Newer Older
何虹's avatar
何虹 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
// 写一个递归方法把请求回来的数据 依次遍历 替换值
import commonUtility from '../funTools/commonUtility'
const parseUrlQueryParams = commonUtility.parseUrlQueryString() || {}
const parseGlobalParams = commonUtility.parseGlobalParams() || {}
function recursiveFun(obj) {
  const objType = typeof obj
  if (Array.isArray(obj)) {
    obj.forEach((item) => {
      recursiveFun(item)
    })
  } else if (objType === 'object') {
    for (const prop in obj) {
      recursiveFun(obj[prop])
    }
  } else {
    obj = commonUtility.parseMenuGlobalParams(obj, parseUrlQueryParams, parseGlobalParams)
  }
}

const obj = {
  'init_data': {
    'columns': {
      'usable': 1,
      'type': 100
    },
    'exec_sql': 'select bill_date=getdate()',
    'exec_js': 'funcA'
  },
  'entity': {
    'index': {
      'isShowEdiAreaTree': true,
      'defaultProps': {
        'children': 'childs',
        'label': 'equipment_type'
      },
      'isTree': false,
      'table_name': 'emEquipmentType',
      'primaryKey': 'id',
      'queryMainParms': [
        'equipment_type_id=id'
      ],
      'indexTitle': '设备类型',
      'dyncQueryParms': {
        'ort': '11',
        'bb_name': '{menuParam.name}'
      }
    },
    'main': {
      'table_name': 'emEquipmentModel',
      'primaryKey': 'id',
      'is_master_detail': true,
      'dyncQueryParms': {
        'number': '12312',
        'th_name': '{menuParam.name}'
      }
    }
  },
  'new_default': {
    'main': {
      'copy_prerow': 'column1,column2',
      'only_set_null_field': true,
      'columns': {
        'name': '{menuParam.name}',
        'type': 100
      },
      'exec_sql': 'select bill_date=getdate()',
      'exec_js': 'funcA'
    }
  },
  'required_column': {
    'columns': [
      {
        'name': 'column1',
        'null_value': 0
      },
      {
        'name': 'column2'
      }
    ],
    'exec_sql': 'select bill_date=getdate()',
    'exec_js': 'funcA'
  },
  'custom': {
    'bill_type': 100
  }
}
recursiveFun(obj)
console.log(obj)