我有以下json结构:
"disputas": [
{
id: "",
tipo_negociacao: "",
historico:{
fl_usuario: "",
created_at: "",
updated_at: "",
created_by: null,
updated_by: null,
texto: "",
}
}
]
我正在使用http.put
更新此json,我想在每次单击按钮时创建另一个historico
对象,所以它看起来像这样:
"disputas": [
{
id: "",
tipo_negociacao: "",
historico:{
fl_usuario: "",
created_at: "",
updated_at: "",
created_by: null,
updated_by: null,
texto: "",
},
historico:{
fl_usuario: "",
created_at: "",
updated_at: "",
created_by: null,
updated_by: null,
texto: "",
}
}
]
我该怎么做?
这是我的服务:
url: string = 'http://localhost:3004/disputa';
constructor(private http: Http){}
atualizaDisputa (body:Object): Observable<DisputaPropostaComponent[]>{
let bodyString = JSON.stringify(body); // Stringify payload
let headers = new Headers({ 'Content-Type': 'application/json' }); // ... Set content type to JSON
let options = new RequestOptions({ headers: headers }); // Create a request option
return this.http.put(`${this.url}/${body['id']}`, body, options) // ...using post request
.map((res:Response) => res.json()) // ...and calling .json() on the response to return data
.catch((error:any) => Observable.throw(error.json().error || 'Ocorreu um erro em nosso servidor, tente novamente mais tarde')); //...errors if any
}
提前致谢。如果你们需要更多代码,请告诉我。
答案 0 :(得分:1)
你不能在一个对象上有两个名为historico的键。您需要将其转换为数组。一旦你这样做,你可以像往常一样推进阵列。