[英]How do I access a Parse objects properties?
I'm running the following in my Parse background job: 我在Parse后台作业中运行以下命令:
var pushIncrement = Parse.Object.extend("pushIncrement");
var pushIncrementQuery = new Parse.Query(pushIncrement);
pushIncrementQuery.equalTo('objectId', 'hKj2Eazz6h');
pushIncrementQuery.find({
success: function(results) {
console.log('Here are the results:' + results);
status.success("Completed successfully.");
},
error: function(error) {
console.log('shit');
status.error('shitty shit');
}
});
results
is a Parse object. results
是一个Parse对象。 If for instance, I was querying all matchCenterItem
objects, results
would be returned with a format like this: 例如,如果我正在查询所有
matchCenterItem
对象,则将以如下格式返回results
:
<matchCenterItem: 0x7f84e2c1a4b0, objectId: Je1VxP7dPw, localId: (null)> {
categoryId = 9355;
itemCondition = Used;
itemLocation = US;
maxPrice = 350;
minPrice = 250;
parent = "<PFUser: 0x7f84e2c20c10, objectId: kfEHfG4FUD>";
searchTerm = "iphone 5 unlocked";
}
Now if I wanted to access for example, the categoryId
property of results
and console log it, how would I do that? 现在,如果要访问例如
results
的categoryId
属性并将其记录在控制台上,我该怎么做? I tried something like the following in the success function, but it didn't work as I expected: 我在成功函数中尝试了以下类似的操作,但是没有按预期工作:
console.log('Here's the categoryId:' + results.categoryId);
Figured it out, can do it like this: 想通了,可以这样做:
var pushIncrement = Parse.Object.extend("pushIncrement");
var pushIncrementQuery = new Parse.Query(pushIncrement);
pushIncrementQuery.equalTo('objectId', 'hKj2Eazz6h');
pushIncrementQuery.find({
success: function(results) {
for (var i = 0; i < results.length; ++i) {
var dayNumber = results[i].get("Number");
}
console.log('dem results be:' + dayNumber);
status.success("Push Notifications completed successfully.");
},
error: function(error) {
console.log('shit');
status.error('shitty shit');
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.