gpt4 book ai didi

javascript - 如何使用 javascript 显示来自 parse.com 数据库的图像?

转载 作者:行者123 更新时间:2023-11-30 08:50:13 24 4
gpt4 key购买 nike

我正在寻找有关如何使用 javascript 从我的 Parse 数据库中以 HTML 格式显示图像的答案。事实证明,通读 parse.com 上的文档帮助不大。

我存储图像的类称为“内容”。图像作为文件存储在名为“图像”的列中。

最佳答案

来自Parse JavaScript Guide :

How to best retrieve the file contents back depends on the context of your application. Because of cross-domain request issues, it's best if you can make the browser do the work for you. Typically, that means rendering the file's URL into the DOM. Here we render an uploaded profile photo on a page with jQuery:

var profilePhoto = profile.get("photoFile");
$("profileImg")[0].src = profilePhoto.url();

所以你的步骤可能是这样的:

  1. 查询包含所需图片的行的内容类
  2. 获取图片的URL
  3. 设置图像元素的来源

下面是一些示例代码:

    // Query the content class for rows where the image exists
var Content = Parse.Object.extend("content");
var query = new Parse.Query(Content);
query.exists("image");
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('image'));
}
// If the imageURLs array has items in it, set the src of an IMG element to the first URL in the array
if(imageURLs.length > 0){
$('#color').attr('src', imageURLs[0]);
}
},
error: function(error) {
// If the query is unsuccessful, report any errors
alert("Error: " + error.code + " " + error.message);
}
});

关于javascript - 如何使用 javascript 显示来自 parse.com 数据库的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18553290/

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