更简洁的实现数组赋值的方法,数组子元素是对象类型

数组为:

  basicInfos: [
    { label: '采购商租户', value: '', span: '8', xlSpan: '4' },
    { label: '采购商名称', value: '', span: '8', xlSpan: '6' },
    { label: '登录账号', value: '', span: '8', xlSpan: '4' },
    { label: '供应商编码', vale: '', span: '8', xlSpan: '4' },
    { label: '三证合一码', value: '', span: '8', xlSpan: '4' },
    { label: '状态', value: '', span: '8', xlSpan: '2' },
  ],

现对数组中的每一个value进行初始化赋值,Lodash有比较优雅的方法赋值吗?现在赋值实现是这样的:

  this.basicInfos[0].value = supplierAndPurchaseDto.tenantId
  this.basicInfos[1].value = supplierAndPurchaseDto.enterpriseName
  this.basicInfos[2].value = supplierAndPurchaseDto.loginAccount
  this.basicInfos[3].value = supplierAndPurchaseDto.partner
  this.basicInfos[4].value = supplierAndPurchaseDto.licenseCode
  this.basicInfos[5].value = supplierAndPurchaseDto.supplierStatusName
阅读 1.4k
1 个回答
let supplierAndPurchaseDtoMap = ['tenantId','enterpriseName','loginAccount','partner','licenseCode','supplierStatusName'];

this.basicInfos.map((item,index)=>{
    let key = supplierAndPurchaseDtoMap[index];
    item.value = supplierAndPurchaseDto[key];
    return item;
})
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题