samedi 27 juin 2015

saveAll() works but throws an error

I'm developing an app on iOS. I am updating my Users custom 'Rank' field based on their ordered 'Time01' field so they can be ordered on a scoreboard.

The code updates the 'Rank' fields but I get an error response.

This is my code...

Parse.Cloud.define("updateRanks", function(request, status) {
    var query = new Parse.Query(Parse.User);
    query.ascending('Time01');
    query.find({
        success: function(users) {
            for (var i = 0; i < users.length; i++) { 
                users[i].set("Rank", i + 1);
            }
            Parse.Object.saveAll(users, {
                    useMasterKey: true,
                    success: function(result) {
                            response.success();
                    },
                    error: function(error) {
                            response.error(error);
                    }
                });
        },
        error: function(error) {
            response.error(error);
        }
    });
});

And this is the error I get...

2015-06-28 15:34:46.276 Juggs[1188:166690] [Error]: ReferenceError: response is not defined
    at Parse.Object.saveAll.success (main.js:205:24)
    at Parse.js:2:7765
    at e (Parse.js:2:6545)
    at Parse.js:2:5994
    at Array.forEach (native)
    at Object.x.each.x.forEach [as _arrayEach] (Parse.js:1:664)
    at c.extend.resolve (Parse.js:2:5945)
    at e (Parse.js:2:6680)
    at Parse.js:2:5994
    at Array.forEach (native) (Code: 141, Version: 1.6.1)

I have called response.success() in the saveAll call so I'm wondering why I am getting this error? Any help would be much appreciated.

Aucun commentaire:

Enregistrer un commentaire