javascript - Parse.com Cloud Code : Can't save data browser object -


i'm using following code delete currentuser user friend list.

result.set("dateuserlist", datelistarr);  

this works, but:

result.save(); 

doesn't work - when checking data browser don't see changes.

parse.cloud.define("hello", function(request, response) { 

response.success("hello world!"); });

parse.cloud.define("deleteuserfromdatelist", function (request, response) {

var usertodelete = string(request.params.currentuser); var user = string(request.params.dateid);  var query = new parse.query("user"); query.equalto("fbid", user);  query.first(            {                success: function (result)                {                    var datelistarr = result.get("dateuserlist");                        for(j = 0 ; j < datelistarr.length;j++)                        {                            if (datelistarr[j] == usertodelete)                            {                                console.log("found match");                                datelistarr.splice(j);                                console.log("deleted");                                break;                            }                        }                         console.log(datelistarr);                        result.set("dateuserlist", datelistarr);                         result.save().then(function (savedobj)                        {                            response.success(usertodelete + "is deleted " + user + " friend list");                         },                        function (saveerror)                        {                             response.error("unable create object");                         });                 },                error: function () {                    response.error("error occured on user deletion");                }            }); 

});

the save asynchronous, , you're not waiting finish before calling response.success(). use promise syntax call success when result saved instead.

result.save().then(function(obj) {   response.success(....  }, function(err) {   ...  }); 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -