Array of objects on a json
This question already has an answer here:
只需将新项目推送至历史数组:
this.disputa.historico.push({
fl_usuario: "",
created_at: "",
updated_at: "",
created_by: null,
updated_by: null,
texto: ""
});
只需追加一个数组:
this.disputa.historico.push({/* your object here*/});
You run into the error
Cannot set property 'texto' of undefined
when you try to access a property on a undefined or null object.
You will first have to create a empty object in its place, if not already existing. The way your code is, it is expecting the object to be present in the index you are trying to access.
var existingObj = this.disputa.historico[this.i];
// if the value is falsy, then go ahead and create
// an empty object at that index
if(!existingObj) {
this.disputa.historico[this.i] = {};
}
existingObj.texto = "something";
链接地址: http://www.djcxy.com/p/17944.html
下一篇: json上的对象数组