javascript - Array of objects on a json - http put -
this question has answer here:
- how append array? 22 answers
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
Post a Comment