当我打印用户时,我得到:{" objectId":" insertSomeValue"}作为输出。但我无法获取该objectId的值并将其存储在字符串变量中。我如何获得它?
我尝试了user.get(" objectId")和用户[" objectId"]但他们只是返回"没有提供消息"当送到console.log时。在获得objectId之前,我是否必须获取用户?
var query = new Parse.Query("HelperRating");
var newProfiles = {};
var eachPromise = Parse.Promise.as();
eachPromise = eachPromise.then(function() {
return query.each(
function (helperRating) {
var user = helperRating.get("helper");
var userId = user.objectId; // How do I get this?
console.log(user);
console.log(user.get("objectId")); // I tried these but it prints "No message provided" instead
//console.log(user["objectId"]);
var newRating = helperRating.get("rating");
// Calculate without querying
if (newProfiles.hasOwnProperty(userId)) {
newProfiles[userId][0] = 10;
} else {
newProfiles[userId] = [];
newProfiles[userId].push(1);
}
return;
}
);
return eachPromise;
}).then(function(){
var promises = [];
for (var userId in newProfiles) {
if (newProfiles.hasOwnProperty(userId)) {
var query = new Parse.Query("UserProfile");
query.equalTo("owner", userId);
var promise = query.find().then(
function (results) {
// Do something
}
);
promises.push(promise);
}
}
return Parse.Promise.when(promises);
});
答案 0 :(得分:2)
JS SDK中的objectId由var userId = user.id