Welcome
Login
Sign up
Home
Solutions
Forums
How can we help you today?
Enter your search term here...
Search
Login
or
Signup
to submit a new ticket
Check ticket status
Start a new topic
Discussions
Kinvey Forums
JavaScript
Appending objects to an Array (HTML5 - JS)
J
Jose Gomez
started a topic
over 7 years ago
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
e
evenemento
said
over 7 years ago
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
More topics in
JavaScript
How do I use Kinvey in my web app?
Is it safe to include keys/secrets in my client-side JavaScript app?
Why is the activeUser null even though I am logged in?
Login does not work even though credentials are valid.
Social login doesn’t work.
New to node.js - need bootstrap to downloadfiles from Kinvey
Problem with Aggregation/Grouping
Internal Server Error using Twitter Sign Up
Data Store
See all 315 topics
Jose Gomez
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 ;)