如何在查询运行后将以下查询结果保存到变量中?
例如,我想只捕获profileURL: Badgeresults[i].get('SentTo').get('pic'),
我想将它保存到变量中,以便我可以在div中引用它以显示在页面上。
无法在SO上找到直接回答此问题的问题......
query.find({
success: function(Badgeresults) {
// If the query is successful, store each image URL in an array of image URL's
var Badges = [];
for (var i = 0; i < Badgeresults.length; i++) {
Badges.push({
imageURL: Badgeresults[i].get('Global_Badges_img'),
categorySelected: Badgeresults[i].get('category'),
badgeNameSelected: Badgeresults[i].get('BadgeName'),
AwardedBy: Badgeresults[i].get('uploadedBy').get('username'),
AwardedTo: Badgeresults[i].get('SentTo').get('username'),
profileURL: Badgeresults[i].get('SentTo').get('pic'),
comment: Badgeresults[i].get('Comment'),
});
}
答案 0 :(得分:1)
从var Badges = [];
query.find({
var Badges = [];
query.find({
success: function(Badgeresults) {
// If the query is successful, store each image URL in an array of image URL's
for (var i = 0; i < Badgeresults.length; i++) {
Badges.push({
imageURL: Badgeresults[i].get('Global_Badges_img'),
categorySelected: Badgeresults[i].get('category'),
badgeNameSelected: Badgeresults[i].get('BadgeName'),
AwardedBy: Badgeresults[i].get('uploadedBy').get('username'),
AwardedTo: Badgeresults[i].get('SentTo').get('username'),
profileURL: Badgeresults[i].get('SentTo').get('pic'),
comment: Badgeresults[i].get('Comment'),
});
}