直接从Parse.com的JavaScript指南 :
var GameScore = Parse.Object.extend("GameScore");
var query = new Parse.Query(GameScore);
query.get("xWMyZ4YEGZ", {
success: function(gameScore) {
// The object was retrieved successfully.
},
error: function(object, error) {
// The object was not retrieved successfully.
// error is a Parse.Error with an error code and message.
}
});
var score = gameScore.get("score");
var playerName = gameScore.get("playerName");
var cheatMode = gameScore.get("cheatMode");
基本上给出了未捕获的ReferenceError:gameScore没有定义...
这里是我的代码来解决此:
// Retrieve class
var GameScore = Parse.Object.extend("GameScore"); //redefine the GameScore class based on the cloud.
var query = new Parse.Query(GameScore);
var my_object;
var some_object = query.get("SQV1DZXv5p", {
success: function(gameScore) { //gameScore is the retrieved object.
alert('Object retrieved, with 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 will be NULL if not found.
}
});
var score = gameScore;
document.getElementById('division1').innerHTML = my_object;
因此,这仍然抛出了引用错误gameScore
。 此外, document.getELementById
语句不打印gameScore.id
我division1
股利。 它仍然是空的。 但是,当我检查,看看有什么my_object
是在JavaScript控制台,它返回gameScore.id
正确。
有趣的是,如果我运行document.getELementById
成功函数内线 ,那么它会显示gameScore.id
...