Parse retrieve pointer from current user in javascript - Stack Overflow

In Parse I have the User table set up with a number of columns, most of which are Strings but one is a

In Parse I have the User table set up with a number of columns, most of which are Strings but one is a Pointer to another Parse Class. I want to use this pointer in a query

In Java I can access the pointer to use in my query as follows:

ParseUser currentUser = ParseUser.getCurrentUser();
ParseObject Parent = currentUser.getParseObject("ComParent");

In JavaScript I have tried using:

var currentUser = Parse.User.current();
var Parent = currentUser.get("ComParent");

But this returns undefined. What am I doing wrong?

In Parse I have the User table set up with a number of columns, most of which are Strings but one is a Pointer to another Parse Class. I want to use this pointer in a query

In Java I can access the pointer to use in my query as follows:

ParseUser currentUser = ParseUser.getCurrentUser();
ParseObject Parent = currentUser.getParseObject("ComParent");

In JavaScript I have tried using:

var currentUser = Parse.User.current();
var Parent = currentUser.get("ComParent");

But this returns undefined. What am I doing wrong?

Share Improve this question asked Jan 10, 2015 at 18:31 Mark__CMark__C 8251 gold badge15 silver badges25 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

According to the documentation:

"By default, when fetching an object, related Parse.Objects are not fetched. These objects' values cannot be retrieved until they have been fetched like so:"

var post = fetchedComment.get("parent");
post.fetch({
  success: function(post) {
    var title = post.get("title");

  }
});

So you should write:

var currentUser = Parse.User.current();
var Parent = currentUser.get("ComParent");
Parent.fetch({
    success: function(Parent) {
        var name = Parent.get("Name");
        alert(name); // this one will work
    }
});
alert(Parent.get("Name")); // this one wont work, see below

Just remember that success is an asynchronous callback,as such Parent will not be available outside the success function as shown above, if you need to access Parent outside of success check out https://stackoverflow./a/27673839/1376624

Thanks. My issue was a bination of 2 things. Firstly, I was not correctly fetching the object as you rightly point out. Secondly, I was trying to fetch an object from a user which did not have an associated ComParent object (Doh!). Anyway, your solution put me onto the need to fetch the object but I don't think it is the currentUser that should have the fetch, it is Parent:

var currentUser = Parse.User.current();
var Parent = currentUser.get("ComParent");
    Parent.fetch({
        success: function(Parent) {
            var name = Parent.get("Name");
            alert(name);
        }
    });

Thanks again @DelightedD0D

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745269326a4619647.html

相关推荐

  • Parse retrieve pointer from current user in javascript - Stack Overflow

    In Parse I have the User table set up with a number of columns, most of which are Strings but one is a

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信