为了账号安全,请及时绑定邮箱和手机立即绑定

将数组中的项插入到一个对象之中

将数组中的项插入到一个对象之中

慕无忌1623718 2019-04-27 22:16:29
题目描述将一个数组中的项插入到一个对象中vardragObj={dragItem:[{itemName:"正面像",itemImgList:[]},{itemName:"正面微笑像",itemImgList:[]},{itemName:"侧面90°像",itemImgList:[]}]};vardataObjArr=[{"id":1407,"categoryId":"58424971ace94fab9b05dcd0b2134f77","imageName":"正面像","imageUrl":"http://cdn.ormco.synconize.com/ffc9096c809a4f2ba1c8ae2020bce7bc","orderSort":1},{"id":1418,"categoryId":"58424971ace94fab9b05dcd0b2134f77","imageName":"正面微笑像","imageUrl":"http://cdn.ormco.synconize.com/1cf5931ccb4543769544ff2145291756","orderSort":2},{"id":1409,"categoryId":"58424971ace94fab9b05dcd0b2134f77","imageName":"侧面90°像","imageUrl":"http://cdn.ormco.synconize.com/38790c6d7d49416f9c181dd726a53abe","orderSort":3}];目标:生成一个新的对象newObj,或者通过映射到dragObjvarnewObj={dragItem:[{itemName:"正面像",itemImgList:[{"id":1407,"categoryId":"58424971ace94fab9b05dcd0b2134f77","imageName":"正面像","imageUrl":"http://cdn.ormco.synconize.com/ffc9096c809a4f2ba1c8ae2020bce7bc","orderSort":1}]},{itemName:"正面微笑像",itemImgList:[{"id":1418,"categoryId":"58424971ace94fab9b05dcd0b2134f77","imageName":"正面微笑像","imageUrl":"http://cdn.ormco.synconize.com/1cf5931ccb4543769544ff2145291756","orderSort":2}]},{itemName:"侧面90°像",itemImgList:[{"id":1409,"categoryId":"58424971ace94fab9b05dcd0b2134f77","imageName":"侧面90°像","imageUrl":"http://cdn.ormco.synconize.com/38790c6d7d49416f9c181dd726a53abe","orderSort":3}]}]};
查看完整描述

2 回答

?
当年话下

TA贡献1890条经验 获得超9个赞

dragObj.dragItem.forEach(item=>{
item.itemImgList.push(dataObjArr.find(obj=>obj.imageName==item.itemName))
})
                            
查看完整回答
反对 回复 2019-04-27
  • 2 回答
  • 0 关注
  • 320 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信