如何从 localStorage 获取数组并将其存储在对象中?

时间:2021-06-16 12:13:48

标签: angular typescript

我已将表单值存储在 localStorage 中,我正在获取该数据并将其存储在对象中(我想稍后通过 POST 请求发送该对象),在我有多个数组的对象之一中,我该如何处理将它们存储在我的对象中?

.ts

     get data(): any {
        return JSON.parse(localStorage.getItem('policy'));
      }
       this.personalInfo = {
          personalInfoId: 0,
          insurerInfo: {
             firstName:  this.data.calculatorInfo.name,
             lastName : this.data.calculatorInfo.surname,
             phoneNumber: this.data.contactInfo.phone,
             email: this.data.contactInfo.email,
             personalNumber: this.data.calculatorInfo.personalNumber,
             address: "string"
          },
          legalHeir:true,
          underageChildInfo: [
            {
              firstName: this.data.underageChildInfo.name,
            }
             ]
}

这是我的密钥(策略)值:

{
   "contactInfo":{
      "email":"fvreferf@gmail.com",
      "phone":"568552255"
   },
   "underageChildInfo"?
      {
         "gender":"F",
         "name":"test",
         "surname":"test2",
         "personalNumber":"02027041738",
         "birthDate":"2021-06-26T21:48:17.000Z"
      },
      {
         "gender":"M",
         "name":"test3",
         "surname":"test4",
         "personalNumber":"02027041738",
         "birthDate":"2021-06-25T21:16:32.000Z"
      }
   ]
}

0 个答案:

没有答案