先看数据,后台返回的数据是个大对象。我们称为父对象,子集为数组或对象,孙子集统一为对象,要根据孙子集对象的某一个属性过滤,这里是根据type,过滤掉type 非 eldata,elinput,elimageMore的对象,返回新的一个大对象。
其中样品和检测项目为数组,数组里面都是对象。且需要根据对象的type来过滤。最后面有数据,可以拷贝然后执行。
res 是最大的对象,用for in 循环判断。然后判断是否为数组 和是否为对象,再分别操作。
对对象的操作,其实还是用到数组的方法,先用数组过滤到属性,然后再把剩下的属性拷贝到新的对象里。
let obj = {}
for(let key in res){
console.log(res[key])
if(Array.isArray(res[key])){
obj[key] = []
console.log(res[key],11111)
res[key].forEach((item,index) =>{
obj[key][index] = {}
let arr = []
arr = Object.keys(item).filter(itm =>{
return item[itm].type == 'elinput' || item[itm].type == 'eldate' || item[itm].type == 'elimageMore'
})
arr.forEach(itm=> {
obj[key][index][itm] = res[key][index][itm]
})
})
}
if(Object.prototype.toString.call(res[key]) === '[object Object]'){
obj[key] = {}
let arr = []
arr = Object.keys(res[key]).filter(item =>{
return res[key][item].type == 'elinput' || res[key][item].type == 'eldate' || res[key][item].type == 'elimageMore'
})
arr.forEach(itm=> {
obj[key][itm] = res[key][itm]
})
console.log(obj)
}
}
/// 下面是后台返回的数据。
res =
{
"申请单": {
"编号": {
"value": "A0001",
"type": "elinput",
"width": "160px",
"label": "编号",
"code": "model.order.order.Order.number"
},
"客户": {
"value": "蒋介石",
"type": "elinput",
"width": "240px",
"label": "客户",
"code": "model.order.order.Order.customer.name"
},
"客户经理": {
"value": "胡一刀2",
"type": "elrSelect",
"width": "100px",
"label": "客户经理",
"code": "model.order.order.Order.owner.name"
},
"联系人": {
"type": "elinput",
"width": "104px",
"label": "联系人",
"code": "model.order.order.Order.customer.contactName"
},
"联系电话": {
"type": "elinput",
"width": "130px",
"label": "联系电话",
"code": "model.order.order.Order.customer.contactPhone"
},
"联系地址": {
"type": "elinput",
"width": "180px",
"label": "联系地址",
"code": "model.order.order.Order.customer.contactAddress"
},
"录入时间": {
"type": "eldate",
"width": "110px",
"label": "录入时间",
"code": "model.order.order.Order.inputTime"
},
"备注信息": {
"value": "",
"type": "elinput",
"webType": "elinput",
"width": "160px",
"label": "备注信息",
"code": "model.order.order.Order.remark"
},
"优先级": {
"value": "正常",
"type": "elinput",
"webType": "elinput",
"width": "160px",
"label": "优先级",
"code": "model.order.order.Order.priority"
}
},
"检测项目": [
{
"名称": {
"value": "A123",
"type": "elinput",
"width": "160px",
"label": "名称",
"code": "model.order.item.Item.name"
},
"章节号": {
"value": "5",
"type": "elinput",
"width": "80px",
"label": "章节号",
"code": "model.order.item.Item.section"
},
"标准名": {
"value": "R",
"type": "elinput",
"width": "160px",
"label": "标准名",
"code": "model.order.item.Item.standardName"
},
"检测值": {
"value": "31",
"type": "elinput",
"width": "160px",
"label": "检测值",
"code": "model.order.item.Item.value"
},
"检测结论": {
"value": "BAD",
"type": "elinput",
"width": "160px",
"label": "检测结论",
"code": "model.order.item.Item.result"
},
"原始记录表": {
"value": "{\"url\":\"/file/downloads/ent/dev/admin/202209/991af26c-3d61-11ed-93e5-00163e0e4e24.json\",\"pdf_url\":null}",
"type": "elrSheet",
"width": "160px",
"label": "原始记录表",
"code": "model.order.item.Item.notebook.originalRecord"
}
},
{
"名称": {
"value": "A234",
"type": "elinput",
"width": "160px",
"label": "名称",
"code": "model.order.item.Item.name"
},
"章节号": {
"value": "4",
"type": "elinput",
"width": "80px",
"label": "章节号",
"code": "model.order.item.Item.section"
},
"标准名": {
"value": "T",
"type": "elinput",
"width": "160px",
"label": "标准名",
"code": "model.order.item.Item.standardName"
},
"检测值": {
"value": "30",
"type": "elinput",
"width": "160px",
"label": "检测值",
"code": "model.order.item.Item.value"
},
"检测结论": {
"value": "OK",
"type": "elinput",
"width": "160px",
"label": "检测结论",
"code": "model.order.item.Item.result"
},
"原始记录表": {
"value": "{\"url\":\"/file/downloads/ent/dev/admin/202209/9315318e-3d61-11ed-93e5-00163e0e4e24.json\",\"pdf_url\":null}",
"type": "elrSheet",
"width": "160px",
"label": "原始记录表",
"code": "model.order.item.Item.notebook.originalRecord"
}
}
],
"申请单记录": {
"检测日期": {
"value": "2022-09-15 00:00:00",
"type": "eldate",
"width": "110px",
"label": "检测日期",
"code": "model.notebook.notebook.Notebook.testDate"
},
"相册": {
"value": "[{\"filename\":\"video.png\",\"url\":\"/file/downloads/ent/dev/admin/202209/2e92fd8c-3b1c-11ed-8441-00163e0e4e24.png\",\"user_id\":1,\"user_name\":\"管理员\"},{\"filename\":\"omiga.png\",\"url\":\"/file/downloads/ent/dev/admin/202209/2ec38b64-3b1c-11ed-8441-00163e0e4e24.png\",\"user_id\":1,\"user_name\":\"管理员\"},{\"filename\":\"delete.png\",\"url\":\"/file/downloads/ent/dev/admin/202209/2ec94c52-3b1c-11ed-8441-00163e0e4e24.png\",\"user_id\":1,\"user_name\":\"管理员\"},{\"filename\":\"avartor.jpg\",\"url\":\"/file/downloads/ent/dev/admin/202209/2ecf82fc-3b1c-11ed-8441-00163e0e4e24.jpg\",\"user_id\":1,\"user_name\":\"管理员\"},{\"filename\":\"管制大1.png\",\"url\":\"/file/downloads/ent/dev/admin/202209/2ed56fdc-3b1c-11ed-8441-00163e0e4e24.png\",\"user_id\":1,\"user_name\":\"管理员\"},{\"filename\":\"冠治达.png\",\"url\":\"/file/downloads/ent/dev/admin/202209/2edb92a4-3b1c-11ed-8441-00163e0e4e24.png\",\"user_id\":1,\"user_name\":\"管理员\"},{\"filename\":\"guanzhida.png\",\"url\":\"/file/downloads/ent/dev/admin/202209/2ee1c836-3b1c-11ed-8441-00163e0e4e24.png\",\"user_id\":1,\"user_name\":\"管理员\"},{\"filename\":\"erweima.png\",\"url\":\"/file/downloads/ent/dev/admin/202209/2efbc57e-3b1c-11ed-8441-00163e0e4e24.png\",\"user_id\":1,\"user_name\":\"管理员\"},{\"filename\":\"avartor.jpg\",\"url\":\"/file/downloads/ent/dev/admin/202209/36748fde-3b1c-11ed-8441-00163e0e4e24.jpg\",\"user_id\":1,\"user_name\":\"管理员\"},{\"filename\":\"omiga.png\",\"url\":\"/file/downloads/ent/dev/admin/202209/367b0fe4-3b1c-11ed-8441-00163e0e4e24.png\",\"user_id\":1,\"user_name\":\"管理员\"},{\"filename\":\"delete.png\",\"url\":\"/file/downloads/ent/dev/admin/202209/36810a48-3b1c-11ed-8441-00163e0e4e24.png\",\"user_id\":1,\"user_name\":\"管理员\"},{\"filename\":\"video.png\",\"url\":\"/file/downloads/ent/dev/admin/202209/36881b8a-3b1c-11ed-8441-00163e0e4e24.png\",\"user_id\":1,\"user_name\":\"管理员\"},{\"filename\":\"管制大1.png\",\"url\":\"/file/downloads/ent/dev/admin/202209/368dea10-3b1c-11ed-8441-00163e0e4e24.png\",\"user_id\":1,\"user_name\":\"管理员\"},{\"filename\":\"冠治达.png\",\"url\":\"/file/downloads/ent/dev/admin/202209/3693ee1a-3b1c-11ed-8441-00163e0e4e24.png\",\"user_id\":1,\"user_name\":\"管理员\"},{\"filename\":\"guanzhida.png\",\"url\":\"/file/downloads/ent/dev/admin/202209/36b1bcd8-3b1c-11ed-8441-00163e0e4e24.png\",\"user_id\":1,\"user_name\":\"管理员\"},{\"filename\":\"erweima.png\",\"url\":\"/file/downloads/ent/dev/admin/202209/36b7bb6a-3b1c-11ed-8441-00163e0e4e24.png\",\"user_id\":1,\"user_name\":\"管理员\"},{\"filename\":\"lanya.png\",\"url\":\"/file/downloads/ent/dev/admin/202209/36bd3da6-3b1c-11ed-8441-00163e0e4e24.png\",\"user_id\":1,\"user_name\":\"管理员\"},{\"filename\":\"watch.png\",\"url\":\"/file/downloads/ent/dev/admin/202209/36c363e8-3b1c-11ed-8441-00163e0e4e24.png\",\"user_id\":1,\"user_name\":\"管理员\"}]",
"type": "elimageMore",
"webType": "elimageMore",
"width": "160px",
"label": "相册",
"code": "model.notebook.notebook.Notebook.v18369867a3c65b7a096191fd"
},
"原始记录表": {
"value": "{\"url\":\"/file/downloads/ent/dev/admin/202209/2cab2ae0-3d3c-11ed-93e5-00163e0e4e24.json\",\"pdf_url\":null}",
"type": "elrSheet",
"webType": "elrSheet",
"width": "160px",
"label": "原始记录表",
"code": "model.notebook.notebook.Notebook.originalRecord"
},
"测试33333": {
"value": [
{
"filename": "omiga.png",
"url": "/file/downloads/ent/dev/admin/202209/bb8abefe-35aa-11ed-adb5-00163e0e4e24.png",
"userId": 1,
"userName": "管理员"
},
{
"filename": "avartor.jpg",
"url": "/file/downloads/ent/dev/admin/202209/bbb960a6-35aa-11ed-adb5-00163e0e4e24.jpg",
"userId": 1,
"userName": "管理员"
}
],
"type": "elimage",
"webType": "elimage",
"width": "160px",
"label": "测试33333",
"code": "model.notebook.notebook.Notebook.v182ecd97690c3b48ea9cb85d"
},
"单图图片": {
"value": "/file/downloads/www/dev/admin/202209/a6028a4e-35aa-11ed-adb5-00163e0e4e24.png",
"type": "elavatarurl",
"webType": "elavatarurl",
"width": "160px",
"label": "单图图片",
"code": "model.notebook.notebook.Notebook.v183214c2f13608dd40a11351"
},
"报告日期": {
"value": "2022-09-15 00:00:00",
"type": "eldate",
"width": "110px",
"label": "报告日期",
"code": "model.notebook.notebook.Notebook.reportDate"
},
"温度": {
"type": "elinput",
"width": "80px",
"label": "温度",
"code": "model.notebook.notebook.Notebook.temperature"
},
"湿度": {
"type": "elinput",
"width": "80px",
"label": "湿度",
"code": "model.notebook.notebook.Notebook.humidity"
},
"大气压": {
"type": "elinput",
"width": "80px",
"label": "大气压",
"code": "model.notebook.notebook.Notebook.atmosphere"
},
"检测设备": {
"type": "elinput",
"width": "120px",
"label": "检测设备",
"code": "model.notebook.notebook.Notebook.equipments"
}
},
"样品": [
{
"编号": {
"value": "AYP123",
"type": "elinput",
"width": "160px",
"label": "编号",
"code": "model.sample.sample.Sample.number"
},
"测试33333": {
"value": "[{\"filename\":\"delete.png\",\"url\":\"/file/downloads/ent/dev/admin/202209/bb2d0786-3a56-11ed-8861-00163e0e4e24.png\",\"user_id\":1,\"user_name\":\"管理员\"},{\"filename\":\"omiga.png\",\"url\":\"/file/downloads/ent/dev/admin/202209/bb3529f2-3a56-11ed-8861-00163e0e4e24.png\",\"user_id\":1,\"user_name\":\"管理员\"},{\"filename\":\"video.png\",\"url\":\"/file/downloads/ent/dev/admin/202209/bb3b4ff8-3a56-11ed-8861-00163e0e4e24.png\",\"user_id\":1,\"user_name\":\"管理员\"},{\"filename\":\"avartor.jpg\",\"url\":\"/file/downloads/ent/dev/admin/202209/bb4133c8-3a56-11ed-8861-00163e0e4e24.jpg\",\"user_id\":1,\"user_name\":\"管理员\"},{\"filename\":\"管制大1.png\",\"url\":\"/file/downloads/ent/dev/admin/202209/bb47bfd6-3a56-11ed-8861-00163e0e4e24.png\",\"user_id\":1,\"user_name\":\"管理员\"},{\"filename\":\"冠治达.png\",\"url\":\"/file/downloads/ent/dev/admin/202209/bb4e58b4-3a56-11ed-8861-00163e0e4e24.png\",\"user_id\":1,\"user_name\":\"管理员\"},{\"filename\":\"video.png\",\"url\":\"/file/downloads/ent/dev/admin/202209/c2abd834-3a56-11ed-8861-00163e0e4e24.png\",\"user_id\":1,\"user_name\":\"管理员\"},{\"filename\":\"omiga.png\",\"url\":\"/file/downloads/ent/dev/admin/202209/c2b2c2ca-3a56-11ed-8861-00163e0e4e24.png\",\"user_id\":1,\"user_name\":\"管理员\"},{\"filename\":\"avartor.jpg\",\"url\":\"/file/downloads/ent/dev/admin/202209/c2bbcc30-3a56-11ed-8861-00163e0e4e24.jpg\",\"user_id\":1,\"user_name\":\"管理员\"},{\"filename\":\"delete.png\",\"url\":\"/file/downloads/ent/dev/admin/202209/c2c15a56-3a56-11ed-8861-00163e0e4e24.png\",\"user_id\":1,\"user_name\":\"管理员\"},{\"filename\":\"冠治达.png\",\"url\":\"/file/downloads/ent/dev/admin/202209/c2c7690a-3a56-11ed-8861-00163e0e4e24.png\",\"user_id\":1,\"user_name\":\"管理员\"},{\"filename\":\"管制大1.png\",\"url\":\"/file/downloads/ent/dev/admin/202209/c2cdf7fc-3a56-11ed-8861-00163e0e4e24.png\",\"user_id\":1,\"user_name\":\"管理员\"},{\"filename\":\"guanzhida.png\",\"url\":\"/file/downloads/ent/dev/admin/202209/c2ea42f4-3a56-11ed-8861-00163e0e4e24.png\",\"user_id\":1,\"user_name\":\"管理员\"},{\"filename\":\"erweima.png\",\"url\":\"/file/downloads/ent/dev/admin/202209/c2f08df8-3a56-11ed-8861-00163e0e4e24.png\",\"user_id\":1,\"user_name\":\"管理员\"},{\"filename\":\"lanya.png\",\"url\":\"/file/downloads/ent/dev/admin/202209/c2f7b0ce-3a56-11ed-8861-00163e0e4e24.png\",\"user_id\":1,\"user_name\":\"管理员\"},{\"filename\":\"watch.png\",\"url\":\"/file/downloads/ent/dev/admin/202209/c2fd5c7c-3a56-11ed-8861-00163e0e4e24.png\",\"user_id\":1,\"user_name\":\"管理员\"}]",
"type": "elimageMore",
"webType": "elimageMore",
"width": "160px",
"label": "测试33333",
"code": "model.sample.sample.Sample.notebook.v182ecd97690c3b48ea9cb85d"
},
"原始记录表": {
"value": "{\"url\":\"/file/downloads/ent/dev/admin/202209/a07ab95c-301e-11ed-91e4-00163e0e4e24.json\",\"pdf_url\":null}",
"type": "elrSheet",
"webType": "elrSheet",
"width": "160px",
"label": "原始记录表",
"code": "model.sample.sample.Sample.notebook.originalRecord"
},
"单图图片": {
"value": "/file/downloads/ent/dev/admin/202209/15a141c6-3b08-11ed-b6d4-00163e0e4e24.png",
"type": "elavatarurl",
"webType": "elavatarurl",
"width": "160px",
"label": "单图图片",
"code": "model.sample.sample.Sample.notebook.v183214c2f13608dd40a11351"
},
"短号": {
"value": "1",
"type": "elinput",
"width": "80px",
"label": "短号",
"code": "model.sample.sample.Sample.shortNumber"
},
"名称": {
"value": "1",
"type": "elinput",
"width": "80px",
"label": "名称",
"code": "model.sample.sample.Sample.name"
},
"检测结论": {
"value": "合格",
"type": "elrSelect",
"width": "80px",
"label": "检测结论",
"code": "model.sample.sample.Sample.result"
},
"图片": {
"value": [
{
"filename": "canvas.png",
"url": "/file/downloads/ent/dev/admin/202209/a05be976-3016-11ed-86b9-00163e0e4e24.png",
"userId": 1,
"userName": "管理员"
},
{
"filename": "omiga.png",
"url": "/file/downloads/ent/dev/admin/202209/a07ae47a-3016-11ed-86b9-00163e0e4e24.png",
"userId": 1,
"userName": "管理员"
}
],
"type": "elimage",
"width": "80px",
"label": "图片",
"code": "model.sample.sample.Sample.samplePictures"
},
"重量": {
"value": "18",
"type": "elinput",
"width": "80px",
"label": "重量",
"code": "model.sample.sample.Sample.notebook.weight"
},
"型号": {
"value": "A",
"type": "elinput",
"width": "80px",
"label": "型号",
"code": "model.sample.sample.Sample.model"
},
"出厂编号": {
"value": "D",
"type": "elinput",
"width": "100px",
"label": "出厂编号",
"code": "model.sample.sample.Sample.batchNumber"
},
"描述": {
"value": "G",
"type": "elinput",
"width": "80px",
"label": "描述",
"code": "model.sample.sample.Sample.description"
},
"收样时间": {
"value": "2022-09-09 00:00:00",
"type": "eldate",
"width": "110px",
"label": "收样时间",
"code": "model.sample.sample.Sample.receiveTime"
},
"收样人": {
"value": "4",
"type": "elrSelect",
"width": "100px",
"label": "收样人",
"code": "model.sample.sample.Sample.receiveUserId"
},
"状态": {
"value": "已收样",
"type": "elrSelect",
"width": "80px",
"label": "状态",
"code": "model.sample.sample.Sample.state"
}
},
{
"编号": {
"value": "AYP123(1)",
"type": "elinput",
"width": "160px",
"label": "编号",
"code": "model.sample.sample.Sample.number"
},
"测试33333": {
"value": [
{
"filename": "JDS.jpg",
"url": "/file/downloads/ent/dev/admin/202209/1e6fe16a-3bdd-11ed-8705-00163e0e4e24.jpg",
"userId": 1,
"userName": "管理员"
},
{
"filename": "NAO.jpg",
"url": "/file/downloads/ent/dev/admin/202209/1f553210-3bdd-11ed-8705-00163e0e4e24.jpg",
"userId": 1,
"userName": "管理员"
},
{
"filename": "SYW.jpg",
"url": "/file/downloads/ent/dev/admin/202209/1ff4d8e2-3bdd-11ed-8705-00163e0e4e24.jpg",
"userId": 1,
"userName": "管理员"
},
{
"filename": "YGW.jpg",
"url": "/file/downloads/ent/dev/admin/202209/2089be08-3bdd-11ed-8705-00163e0e4e24.jpg",
"userId": 1,
"userName": "管理员"
}
],
"type": "elimageMore",
"webType": "elimageMore",
"width": "160px",
"label": "测试33333",
"code": "model.sample.sample.Sample.notebook.v182ecd97690c3b48ea9cb85d"
},
"原始记录表": {
"value": "{\"url\":\"/file/downloads/ent/dev/admin/202209/38cfe280-3bdd-11ed-8705-00163e0e4e24.json\",\"pdf_url\":null}",
"type": "elrSheet",
"webType": "elrSheet",
"width": "160px",
"label": "原始记录表",
"code": "model.sample.sample.Sample.notebook.originalRecord"
},
"单图图片": {
"value": "/file/downloads/ent/dev/admin/202209/3d7185c8-3bdd-11ed-8705-00163e0e4e24.jpg",
"type": "elavatarurl",
"webType": "elavatarurl",
"width": "160px",
"label": "单图图片",
"code": "model.sample.sample.Sample.notebook.v183214c2f13608dd40a11351"
},
"短号": {
"value": "1",
"type": "elinput",
"width": "80px",
"label": "短号",
"code": "model.sample.sample.Sample.shortNumber"
},
"名称": {
"value": "1",
"type": "elinput",
"width": "80px",
"label": "名称",
"code": "model.sample.sample.Sample.name"
},
"检测结论": {
"value": "合格",
"type": "elrSelect",
"width": "80px",
"label": "检测结论",
"code": "model.sample.sample.Sample.result"
},
"图片": {
"value": [
{
"filename": "canvas.png",
"url": "/file/downloads/ent/dev/admin/202209/a05be976-3016-11ed-86b9-00163e0e4e24.png",
"userId": 1,
"userName": "管理员"
},
{
"filename": "omiga.png",
"url": "/file/downloads/ent/dev/admin/202209/a07ae47a-3016-11ed-86b9-00163e0e4e24.png",
"userId": 1,
"userName": "管理员"
}
],
"type": "elimage",
"width": "80px",
"label": "图片",
"code": "model.sample.sample.Sample.samplePictures"
},
"重量": {
"value": "19",
"type": "elinput",
"width": "80px",
"label": "重量",
"code": "model.sample.sample.Sample.notebook.weight"
},
"型号": {
"value": "B",
"type": "elinput",
"width": "80px",
"label": "型号",
"code": "model.sample.sample.Sample.model"
},
"出厂编号": {
"value": "E",
"type": "elinput",
"width": "100px",
"label": "出厂编号",
"code": "model.sample.sample.Sample.batchNumber"
},
"描述": {
"value": "H",
"type": "elinput",
"width": "80px",
"label": "描述",
"code": "model.sample.sample.Sample.description"
},
"收样时间": {
"value": "2022-09-09 00:00:00",
"type": "eldate",
"width": "110px",
"label": "收样时间",
"code": "model.sample.sample.Sample.receiveTime"
},
"收样人": {
"value": "6",
"type": "elrSelect",
"width": "100px",
"label": "收样人",
"code": "model.sample.sample.Sample.receiveUserId"
},
"状态": {
"value": "检测中",
"type": "elrSelect",
"width": "80px",
"label": "状态",
"code": "model.sample.sample.Sample.state"
}
}
],
"报告": {
"编号": {
"value": "a2133",
"type": "elinput",
"width": "160px",
"label": "编号",
"code": "model.report.report.Report.number"
},
"编制人": {
"value": "6",
"type": "elrSelect",
"width": "100px",
"label": "编制人",
"code": "model.report.report.Report.writeUserId"
},
"样品": {
"value": [
"AYP123",
"AYP123(1)"
],
"type": "viewReportSampleSelect",
"width": "180px",
"label": "样品",
"code": "model.report.report.Report.reportSamples.sample.number"
},
"二维码": {
"value": "/file/downloads/graphic_code/dev/qrcode/a903cf9efa8d16d6a41637b6d5758d19/rpt_406.png",
"type": "viewReportQrcode",
"width": "180px",
"label": "二维码",
"code": "model.report.report.Report.qrCode"
}
},
"当前日期": "2022-09-29"
}