gpt4 book ai didi

javascript - 为什么这不会从对象返回图像以在 html 中显示图像?

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

更新了代码和图像

看起来查询中每个返回对象的图像都是“未定义”

Parse.com 和 JavaScript。

我已经设法让我的代码返回我想要的对象,现在我只想取出“pic”url,以便我可以在 html 页面上显示它。

我已经看过,但很难找到如何提取类的某些属性的示例。

下面显示了我的方法,但这会返回一个错误的网址,如屏幕截图所示。

我在这里做错了什么?

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


var query = new Parse.Query(FriendRequest);
query.include('toUser');
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>
<div id="imgs"></div>

enter image description here

enter image description here

enter image description here

最佳答案

使用“get()”下降堆栈,其中您有一个对象,如下所示:

结果[0].get("toUser").pic

而不是:

结果[0].toUser.pic

在调试器的图片中,results.0.toUser 的类型是“Object”。

我认为不使用 javascript 就无法获得对对象的良好引用

.get(myObject)

由于您没有使用封装解析响应的所有细节的框架(设置集合和模型,使其变得非常容易),因此您必须手动完成,确保您下降的每个步骤都完成您有一个有效的引用/类型来说明 child 是什么。

未定义 results.0.toUser.pic 的原因是您没有正确完成解析。

关于javascript - 为什么这不会从对象返回图像以在 html 中显示图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23714195/

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