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

android - ConstraintLayout: Realign baseline constraint in case if dependent view visibility was set to GONE -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -

c# - Update a combobox from a presenter (MVP) -