用于访问 JavaScript 中指针对象内字段的基本 Parse 查询
Basic Parse query to access a field inside a pointer object in JavaScript
我有一个名为 "Current1" 的 table,我将用户的对象保存为这样的指针:
当我点击这个指针时,我指向 _User table。现在我正在尝试做非常简单的查询。我需要访问用户指针内的用户名,然后在 _User table.
中更新一些内容
我的问题现在是使用指针访问“_User”table中的'username':
var aveGame2 = Parse.Object.extend("Current1");
var query2 = new Parse.Query(aveGame2);
query2.include("user");
query2.find({
success: function(results) {
for (var i = 0; i < results.length; i++)
{
var object = results[i];
//....
var user = object.get('user');
var username = user.get('username'); //<--Error is pointing to this line
//More operation
if(True)//Some conditions
{
Parse.Cloud.useMasterKey();
var query = new Parse.Query(Parse.User);
query.equalTo("username", username);
// Get the first user which matches the above constraints.
query.first({
success: function(anotherUser) {
anotherUser.set("prize", 10);
// Save the user.
anotherUser.save(null, {
success: function(anotherUser) {
// The user was saved successfully.
response.success("Successfully updated user.");
},
error: function(gameScore, error) {
// The save failed.
// error is a Parse.Error with an error code and description.
response.error("Could not save changes to user.");
}
});
},
error: function(error) {
response.error("Could not find user.");
}
});
错误:
[Error]: TypeError: Cannot call method 'get' of undefined
at e.query2.find.success
在检查每个字段数小时后,我意识到我没有为 _User table 设置 ACL,因为 Public 读取。这可能会对其他人有所帮助。
我有一个名为 "Current1" 的 table,我将用户的对象保存为这样的指针:
当我点击这个指针时,我指向 _User table。现在我正在尝试做非常简单的查询。我需要访问用户指针内的用户名,然后在 _User table.
中更新一些内容我的问题现在是使用指针访问“_User”table中的'username':
var aveGame2 = Parse.Object.extend("Current1");
var query2 = new Parse.Query(aveGame2);
query2.include("user");
query2.find({
success: function(results) {
for (var i = 0; i < results.length; i++)
{
var object = results[i];
//....
var user = object.get('user');
var username = user.get('username'); //<--Error is pointing to this line
//More operation
if(True)//Some conditions
{
Parse.Cloud.useMasterKey();
var query = new Parse.Query(Parse.User);
query.equalTo("username", username);
// Get the first user which matches the above constraints.
query.first({
success: function(anotherUser) {
anotherUser.set("prize", 10);
// Save the user.
anotherUser.save(null, {
success: function(anotherUser) {
// The user was saved successfully.
response.success("Successfully updated user.");
},
error: function(gameScore, error) {
// The save failed.
// error is a Parse.Error with an error code and description.
response.error("Could not save changes to user.");
}
});
},
error: function(error) {
response.error("Could not find user.");
}
});
错误:
[Error]: TypeError: Cannot call method 'get' of undefined
at e.query2.find.success
在检查每个字段数小时后,我意识到我没有为 _User table 设置 ACL,因为 Public 读取。这可能会对其他人有所帮助。