我想在Parse.com中保存一个新用户以及一个地址点。我以某种方式工作,虽然它似乎在进一步测试时效果不一致。这是我的代码,大部分时间,console.log显示geoPoint未定义,并且不保存geoPoint。 var geo涉及一个Parse类,它包含基于邮政编码的geoPoints,顺便说一句。
$scope.merchantSignUp = function () {
var user = new Parse.User();
var uZip = $scope.user.zip;
var geo = Parse.Object.extend("Geography");
var geoQuery = new Parse.Query(geo);
geoQuery.equalTo("zip", uZip);
geoQuery.select(["latitude", "longitude"]);
geoQuery.first({
success: function (geoPoint) {
console.log(geoPoint); //undefined
var x = geoPoint.get("latitude");
var y = geoPoint.get("longitude");
//console.log(x);
//console.log(y);
var point = new Parse.GeoPoint({
latitude: x,
longitude: y
});
user.set("username", $scope.user.email);
user.set("password", $scope.user.password);
user.set("zip", $scope.user.zip);
user.set("location", point);
user.signUp(null, {
success: function (user) {
// Hooray! Let them use the app now.
console.log("signup worked")
},
error: function (user, error) {
// Show the error message somewhere and let the user try again.
alert("Error: " + error.code + " " + error.message); //I JUST KNOCKED THIS OUT FOR TESTING!!!
}
})
}
})
}
从Angular HTML调用该函数,传入所有$ scope变量。