将嵌套的对象合并到一个对象里面,删除键名、属性名的空格

先看一下要处理的数据

当一个我们拿到这样的数据是不是很头痛,接下来处理数据

created(){
           let result = [];
           for(let i in this.info){
               let tmp = {
                   balance:this.info[i].balance,
                   realName:this.info[i].realName||'',
                   countryCode: this.info[i].countryCode,
                   name:this.info[i].name,
                   idType:this.info[i].idType,
                   idCard:this.info[i].idCard,
               };

               if(this.info[i].detail){
                   tmp.number=this.info[i].detail.Number.split('/')
                   tmp.userNo=tmp.number[1]||i
                   tmp.ServiceStatus = this.info[i].detail['Service Status']=="正常"?'Y':'N';
                   tmp.ActivationTime = this.info[i].detail['Activation Time']||'';
                   tmp.Validity = this.info[i].detail['Validity']||'';
                   tmp.ActivationExpiry = this.info[i].detail['Activation Expiry']||'';
               }else{
                   tmp.number=['+'+i];
                   tmp.userNo=i;
               }
               tmp.userNo=tmp.userNo.replace('+','')
               result.push(tmp);
           }
           console.log(result)
               
},

效果图

 

posted @ 2023-01-11 16:41  eternityQSL  阅读(30)  评论(0编辑  收藏  举报