gpt4 book ai didi

javascript - 如何访问查询返回的对象以便显示图像?

转载 作者:行者123 更新时间:2023-12-03 12:36:31 25 4
gpt4 key购买 nike

Parse.com 和 JavaScript。

根据屏幕截图,下面的代码返回正确的结果,但是..

如何返回并访问此查询捕获的每个对象?我想使用 _User 类中保存的“pic”列。目前我的图像返回未定义。

    var currentUser = Parse.User.current();  
var FriendRequest = Parse.Object.extend("FriendRequest");


var query = new Parse.Query(FriendRequest);
query.equalTo("fromUser", currentUser);
query.equalTo("status", "Request sent");
//query.exists("pic");
query.find({
success: function(results) {
// If the query is successful, store each image URL in an array of image URL's
imageURLs = [];
for (var i = 0; i < results.length; i++) {
var object = results[i];
imageURLs.push(object.get('pic'));
}
// If the imageURLs array has items in it, set the src of an IMG element to the first URL in the array
for(var j = 0; j < imageURLs.length; j++){
$('#imgs').append("<img src='" + imageURLs[j] + "'/>");
}
},
error: function(error) {
// If the query is unsuccessful, report any errors
alert("Error: " + error.code + " " + error.message);
}
});
// show the signup or login page

</script>

最佳答案

如果图像存储在关系数组“pic”中,该数组是“FriendRequest”中的一个元素,那么您必须执行额外的 RELATION 查询来检索该数组...

this.collection = new UserList();
this.model = this.options.model; // check whether user or role shoul b user
var relation = this.model.relation("users");
this.collection.query = relation.query();
var role = this.model.id;
var rolename = this.model.get("name");
this.collection.fetch();

上面的模块与具有“users”字段的 Parse._Roles 一起使用 - 类型关系的数组

要使用“user”中的关系指针,需要“关系”查询。获取后,在集合中,您将拥有与图像所需的指针数组。

关于javascript - 如何访问查询返回的对象以便显示图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23713134/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com