javascript - Array of objects on a json - http put -


this question has answer here:

i have following json structure on project:

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

i want add new index of historico when click on button don't know how it, want this:

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

so far, i've done (function button calls):

     recusaproposta() {         this.disputa.historico[this.i].texto = "something";            this.i++; } 

now, since i starts on 0 works on first time click on button, if click on again i'll error:

cannot set property 'texto' of undefined

can me? thanks

just push new item historico array:

this.disputa.historico.push({ fl_usuario: "",              created_at: "",              updated_at: "",              created_by: null,              updated_by: null,              texto: "" }); 

Comments

Popular posts from this blog

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

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

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