本文主要是介绍数据结构解构方法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
遇到问题后端返回data{其中对应每一个item的checked和descrip}
{
"code": 200,
"msg": "请求成功",
"time": ,
"data": {
"id": "",
"measureFileDesc": null,
"measure": null,
"approveFile": null,
"approveFileDesc": null,
"startTime": null,
"endTime": null,
"fileMap": {
"approveFile": [
{
"createTime": "",
"updateTime": "",
"createBy": "",
"updateBy": "",
"id": "",
"fileName": "未命名文件.png",
"objectName": "/ng",
"bucketName": "fx2",
"fileSuffix": "png",
"correlationId": "",
"remark": "approveFile",
"modelName": "common",
"fileUrl": ""
}
],
"measureFile": [
{
"createTime": "",
"updateTime": "",
"createBy": "",
"updateBy": "",
"id": "",
"fileName": "未命名文件.png",
"objectName": "42.png",
"bucketName": "fx2",
"fileSuffix": "png",
"correlationId": "a",
"remark": "measureFile",
"modelName": "common",
"fileUrl": ""
}
],
}
},
"success": true
}
initInspectionItems(detail) {//detail是后端返回的数据this.inspectionItems.forEach(item => {item.items.forEach(child => {if (detail[child.checked]) {this.$set(child, 'showDescription', detail[child.checked]);//showDescription是需要赋值的字段,将从接口拿到的对应字段,比如approveFile的值赋值给showDescription。}if (detail[child.checked]) {this.$set(child, 'description', detail[child.descrip]);}if (detail[child.checked]) {this.$set(child, 'showFileList', detail.fileMap[child.checked]);}});});},this.inspectionItems = [{title: '一、文件查验',items: [{question: '是否已按要求取得文件',checked: 'approveFile',descrip: 'approveFileDesc',description: '',showFileList: [],showDescription: '',},],},{title: '二、测量文件',items: [{question: '是否已按要求完成测量',checked: 'measureFile',descrip: 'measureFileDesc',description: '',showFileList: [],showDescription: '',},],},
]
这篇关于数据结构解构方法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!