数据格式转化
1、想要“111,222,333,444,555” 这种格式传给后台;
例子:
let attachmentId =' '
let vo = [{id:11},{id:22},{id:33},{id:44}]
let infoFile = []; //基本信息
onSuccess(vo,) {
let ids = "";
vo.forEach(element => {
if (ids) {
ids = ids + "," + element.id;
} else {
ids = element.id;
}
});
attachmentId = ids;
infoFile.push(.attachmentId);
this.modelForm.basicInformation = infoFile.toString(); // 基本信息
}
2、想要[{id:'123321',name:'rwer'},{id:'123321',name:'frrr'},{id:'123321',name:'wdede'}] 这种格式传给后台;
其中id 是一样的;
// 组装格式
this.data.arrPic = []
for (let i = 0; i < this.data.attachmentId.length; i++) { //数组【‘rwer’,‘frrr’,‘wdede’】
let obj = {}
obj.projectId = this.data.filters.projectId
obj.attachmentId = this.data.attachmentId[i]
this.data.arrPic.push(obj)
}
console.log(this.data.arrPic)
JS字符串及对象的转换
猜你喜欢
转载自blog.csdn.net/weixin_41760500/article/details/104054559
今日推荐
周排行