admin管理员组文章数量:1418400
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 badges2 Answers
Reset to default 7According 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
本文标签: Parse retrieve pointer from current user in javascriptStack Overflow
版权声明:本文标题:Parse retrieve pointer from current user in javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745269325a2650792.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论