I'm having problem with my data property.
data: function() {
return {
conversations:
[
]
}
}
When I make a request to server i get response with data. I store these items in response.data.conversations
. It has property named response.data.conversations[].messages
which is saved in JSON notation and stores multiple items. I don't know how to ADD new items to that field.
That's what I have tried:
for(var i=0; i<response.data.conversations.length; i++) {
for(var j=0; j<this.conversations.length; j++) {
if(response.data.conversations[i].conversation_id == this.conversations[j].conversation_id) {
var obj = JSON.parse(this.conversations[j].messages);
obj.push(JSON.parse(response.data.conversations[i].messages));
this.conversations[j].messages = JSON.stringify(obj);
}
}
}
messages
field? It all depends on what kind of data is in themessages
field.messages
is only one message? Then you can't really add a new object to that. Instead, you want an array of messages. If you can an array, you can do.messages.push(newMessage)