javascript - Create a new Object on Json after click (http.put) -


i have following json structure:

"disputas": [     {       id: "",       tipo_negociacao: "",       historico:{          fl_usuario: "",          created_at: "",          updated_at: "",          created_by: null,          updated_by: null,          texto: "",       }     } ] 

i updating json using http.put, want create object of historico each time click on button, this:

"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: "",       }     } ] 

how can this?

this service:

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 json     let options       = new requestoptions({ headers: headers }); // create request option     return this.http.put(`${this.url}/${body['id']}`, body, options) // ...using post request                      .map((res:response) => res.json()) // ...and calling .json() on response return data                      .catch((error:any) => observable.throw(error.json().error || 'ocorreu um erro em nosso servidor, tente novamente mais tarde')); //...errors if } 

thanks in advance. let me know if guys need more code.

you can't have 2 keys named historico on object. you'll need turn array. once can push onto array usual.


Comments

Popular posts from this blog

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

javascript - Confirm a form & display message if form is valid with JQuery -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -