微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在Angular中将数据放入嵌套的JSON中?

如何解决如何在Angular中将数据放入嵌套的JSON中?

我有这个JSON文件

{mood: [ {

"id":"1","text": "Annoyed","cols": 1,"rows": 2,"color": "lightgreen","route":"/angry","musics": [
  {
  "id": "0","name": "English- Heaven's Peace","image": "images/music.png","link": "https://www.youtube.com/playlist?list=PLPfXrbtn3EgleopO8DiEdsNKgqYZZSEKF","descpription": "Tunes that soothe your pained soul","reviews": [
      {                   
           "name": "abc","rating": 4,"review": "energetic","date": ""
      }
  ]
  },{
   "id": "1","name": "English- Hell's Fire","link": "https://www.youtube.com/playlist?list=PLPfXrbtn3EgmZitRQf1X1iYwWW_nUF44L","descpription": "Beats that match the ones of your heart","reviews": [
       {                   
            "name": "abc","rating": 3.5,"date": ""
       }
   ]
  },{
   "id": "2","name": "hindi","link": "","descpription": "","date": ""
       }            
   ]     
  },{
   "id": "3","name": "Punjabi","link": "https://www.youtube.com/playlist?list=PLPfXrbtn3Egnntch2thUO55YqPQgo4Qh7","date": ""
       }            
   ]     
   },{
   "id": "4","name": "Mix and Match","link": "https://www.youtube.com/playlist?list=PLPfXrbtn3EglN5LVTETqH3ipRLfXmY6MB","rating": 5,"date": ""
       }            
   ]     
  }
  ]
 }]
 }`

我创建了一项服务,该服务应该更新心情部分中的所有更改。

putMood(mood: Mood): Observable<Mood> {
const httpOptions ={
headers: new HttpHeaders({
  'Content-Type': 'application/json'
})
};
return this.http.put<Mood>(baseURL + 'moods/' + mood.id,mood,httpOptions)
.pipe(catchError(this.processHTTPMsgService.handleError));
}

还有一个提交功能,该功能应将我新输入的评论放在json文件的“音乐”部分下的“评论”部分。

onSubmit(){
this.review = this.reviewForm.value;
this.review.date = new Date().toISOString();
this.music.reviews.push(this.review);
this.moodservice.putMood(this.mood)
.subscribe(mood => {
this.mood=mood;
},errmess => {this.mood = null; this.errMess = <any>errmess;});
 }

使用此服务和功能,我的评论上传到JSON文件。我在做什么错了?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。