var Arry=[
{name: "vehicleTravelLicenseCopyBack", id: "a1"},
{name: "vehicleTravelLicenseCopyFront", id: "a2"},
{name: "idCardBack", id: "a3"},
{name: "idCardFront", id: "a4"}
]
为了把上面的东西便成下面的
var ImgObj={
idCardBack: "a1",
idCardFront: "a2",
vehicleTravelLicenseCopyBack: "a3",
vehicleTravelLicenseCopyFront: "a4"
}
- 以前的做法定义一个全量对象
Img: {
vehicleTravelLicenseCopyBack: void 0,
vehicleTravelLicenseCopyFront: void 0,
idCardBack: void 0,
idCardFront: void 0,
}
for (let v of Arry) {
for (let n in this.Img) {
if (v.name === n) {
ImgObj[n] = v.id
}
}
}
2、我这是有多惨,今天才发现最快是这样的
for (let v of Arry) {
imgObj[v.name] = v.id
}
为什么当时用了两个数组,脑子进水了。。。