Start a new topic

Appending objects to an Array (HTML5 - JS)

Hello,



I'm trying to append items to an array. Let me explain. I would like to have the following property in one of the objects of my databsae:



{ history: [ { user : me, action : post, date : today } , {user : you, action : read, date: tomorrow } , { user : he, action : delete } ] }



So, I'm not able (using the JS plugin for HTML5) to add another history element to the array, lets suppose I want to add the following:



{ user : john, action : update, date : someday}



to the list in "history"



I'm trying with the "update" clause but it seems to replace the value in "history" instead of appending the element.



I would appreciate any help ;)
1 Comment

you have to fetch object from Kinvey, add position to history and update



var historyLog = { user : john, action : update, date : someday}



Kinvey.DataStore.get([collection], [key])

.then(function(object) {

object.history.push(historyLog);

return Kinvey.DataStore.save(object);

})

.then(function() {

// success

}, function(err) {

// error

console.log(err);

});
Login or Signup to post a comment