0
我有以下的JSON结构后的Json创建新对象在一个按钮上,所以它看起来像这样:点击(http.put)
"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
}
在此先感谢。让我知道你们是否需要更多的代码。
你的问题不清楚。你想创造的东西,看起来像:历史一:{ fl_usuario: “”, created_at: “”, 的updated_at: “”, CREATED_BY:空, updated_by:空, texto: “”, } 当一个按钮被按下? –
我刚刚编辑了这个问题,我想现在有点更清楚了 –
对象上不能有两个名为historico的键。你需要把它变成一个数组。一旦你这样做,你可以像往常一样推入阵列。 –