backbone.js - Returned gameScore Parse.Object object from Parse.Query.get documentation gives undefined gameScore object -
directly parse.com javascript guide:
var gamescore = parse.object.extend("gamescore"); var query = new parse.query(gamescore); query.get("xwmyz4yegz", { success: function(gamescore) { // object retrieved successfully. }, error: function(object, error) { // object not retrieved successfully. // error parse.error error code , message. } }); var score = gamescore.get("score"); var playername = gamescore.get("playername"); var cheatmode = gamescore.get("cheatmode");
basically gives uncaught referenceerror: gamescore not defined...
here code troubleshoot this:
// retrieve class var gamescore = parse.object.extend("gamescore"); //redefine gamescore class based on cloud. var query = new parse.query(gamescore); var my_object; var some_object = query.get("sqv1dzxv5p", { success: function(gamescore) { //gamescore retrieved object. alert('object retrieved, object id: ' + gamescore.id); //document.getelementbyid('division1').innerhtml = gamescore.id; my_object = gamescore.id; }, error: function(object, error) { alert('retrieval failure, error: ' + error.message + '; object retrieved instead is: ' + object); //object null if not found. } }); var score = gamescore; document.getelementbyid('division1').innerhtml = my_object;
so still throws reference error gamescore
. also, document.getelementbyid
statement not print gamescore.id
in division1
div. remains empty. when check see my_object
in javascript console, returns gamescore.id
correctly.
what's interesting if run document.getelementbyid
line inside success function, display gamescore.id
...
do this:
var gamescore = parse.object.extend("gamescore"); var query = new parse.query(gamescore); query.get("xwmyz4yegz", { success: function(gamescore) { // object retrieved successfully. var score = gamescore.get("score"); var playername = gamescore.get("playername"); var cheatmode = gamescore.get("cheatmode"); }, error: function(object, error) { // object not retrieved successfully. // error parse.error error code , message. } });
gamescore
available in scope of success block, hence uncaught referenceerror. world outside success block not know exists. stuff in there.
also, .get()
makes request server, take time complete. performing operations gamescore
after .get()
method result in accessing object when has not been fetched yet, hence error. see @danh's comment below. network calls this, perform actions on fetched object inside completion block.
Comments
Post a Comment