问题
I am using Parse with javascript. I am trying to get an object and I am following the documentation closely. I still end up with the error
Uncaught TypeError: Cannot read property 'get' of undefined
$(document).ready(function(){
Parse.initialize("myInfo","myInfo");
var count = Parse.Object.extend('overallCount');
var myQuery = Parse.Query(count);
myQuery.get('Gqwk38uUYz', { //HERE IS THE PROBLEM
success: function(count) {
// The object was retrieved successfully.
var myCount = count.get('count');
var updatedCount = myCount+1;
$("#myNum").val(updatedCount);
count.save(null, {
success: function(count) {
count.set('count', updatedCount);
count.save();
},
error: function(model, error) {
// This will be called.
// error is an instance of Parse.Error with details about the error.
if (error.code === Parse.Error.OBJECT_NOT_FOUND) {
alert("Uh oh, we couldn't find the object!");
} else if (error.code === Parse.Error.CONNECTION_FAILED) {
alert("Uh oh, we couldn't even connect to the Parse Cloud!");
}
}
});
},
error: function(object, error) {
// The object was not retrieved successfully.
// error is a Parse.Error with an error code and message.
}
});
});
回答1:
You are getting the error because myQuery is indeed undefined. You have to use "new" to create a query object. It's also good practice to capitalize class names:
var Count = Parse.Object.extend('overallCount');
var myQuery = new Parse.Query(Count);
来源:https://stackoverflow.com/questions/26092517/parse-uncaught-typeerror-cannot-read-property-get-of-undefined