Parse.User.current()没有返回用户对象

时间:2013-05-07 09:21:28

标签: parse-platform

我正在使用Parse.com JS API。使用parse.user方法时

getCurrentUser: function getCurrentUser(callback)
        {
            var currentUser = Parse.User.current();
            callback(currentUser);
        }

那会让我回来:

result of the code 1

因为我真的对这个对象的属性感兴趣,所以我需要做这样的事情:

getCurrentUser: function getCurrentUser(callback)
        {
            var currentUser = Parse.User.current();
            //Not quite sure why I need to do that but I fugre out I cannot not really get the user object without
            var userObject = new Object();

            userObject.nick =  currentUser.attributes.nick;
            userObject.gender =  currentUser.attributes.gender;
            userObject.favoriteGenre = currentUser.favoriteGenre;

            callback(userObject);
        }

在我看来这有点肮脏的方式呢?

有没有更好的方法来克服这个障碍?

请注意,我使用的方法是Parse.User.current();所以我可以保存到parse.com的电话,并从本地存储中获取信息。

提前致谢!

修改

我刚刚看到我也可以使用:

Parse.User.current().get("nick");

这看起来更干净,只是让我想想如果我在某些情况下消耗我的parse.com电话比我想要的多。有人知道吗?

1 个答案:

答案 0 :(得分:2)

你是对的"得到"是更清洁的方式。 API调用由客户端 - 服务器API调用测量。如果你获取整个用户对象,那就是一个API调用;如果用户是从localStorage加载的,则没有。财产访问是一项免费的本地操作。

相关问题