[英]Basic Parse query to access a field inside a pointer object in JavaScript
我有一個名為“ Current1”的表,該表將用戶的對象保存為指針,如下所示:
當我單擊該指針時,我將直接指向_User表。 現在,我正在嘗試做一個非常簡單的查詢。 我需要訪問用戶指針內的用戶名,然后再更新_User表中的內容。
我的問題是現在使用指針訪問“ _User”表中的“用戶名”:
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表的ACL設置為Public read。 這可能會幫助其他人。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.