曹え 5811 发布于:2022-06-22 06:02:50
原始数据
{ "id": "231", "title": "捷克", "tid": "13", "molds": "article", "htmlurl": "qqbt", "keywords": null, "description": "帕尔杜比采", "seo_title": "捷克", "userid": "1", "pho": "/static/upload/2022/06/22/202206227368.jpg||/static/upload/2022/06/22/202206221779.png||/static/upload/2022/06/22/202206224073.png", }
重构结果
{ "pic": [ { "url": "/static/upload/2022/06/22/202206227146.png", "name": "" }, { "url": "/static/upload/2022/06/22/202206223985.png", "name": "" }, { "url": "/static/upload/2022/06/22/202206228817.png", "name": "" } ], "tit": "匈牙利", "desc": "科马罗姆" }
重构方法
// 格式化数据 cglist(arr){ let ur,name let pic = arr.pho.split('||') let pics = [] pic.forEach(rs=>{ if(rs.indexOf('|')==-1){ ur = rs name = '' }else{ let rst = rs.split('|') ur = rst[0] name = rst[1] } pics.push({'url':ur,'name':name}) }) let tit = arr.title let desc = arr.description return {'pic':pics,'tit':tit,'desc':desc} }
注意事项
图片通过||分割
有些图片有名称会用|分割
以上方法适用于有无标题均可
登录后可以留言提问!
微信扫码登录