【发布时间】:2017-11-11 04:41:57
【问题描述】:
我正在为我的数据库使用 Firestore,并希望用我从中收到的详细信息填充我的 HTML。 下面是填充我的 HTML 的连接和 javascript 方法:
db.collection("Ingredients2").where("Category", "==",
0).get().then(snapshot => {
snapshot.forEach(doc => {
//get database information
const price = doc.data().Price;
const name = doc.data().Name;
const id = doc.data().IngredientID;
const image = doc.data().Photo;
//create elements
var button = document.createElement("button");
button.className = "imgButton";
var divbunname = document.createElement("bunname" + id);
divbunname.className = "imgName";
var divbunimage = document.createElement("bunimage" + id);
divbunimage.className = "imgPicture";
var divbunprice = document.createElement("bunprice" + id);
divbunprice.className = "imgPrice";
var image1 = document.createElement("img" + id);
image1.className = "imgPicture img";
divbunprice.innerHTML = price;
divbunname.innerHTML = name;
image1.src = image;
document.getElementById("bunstab").appendChild(button);
button.appendChild(divbunname);
button.appendChild(divbunimage);
divbunimage.appendChild(image1);
button.appendChild(divbunprice);
});
})
.catch(err => {
console.log('Error getting documents', err);
});
这会填充名称和价格,但不会出现图像。这是我的 CSS:
.imgButton {
position: relative;
cursor: pointer;
border: none;
background-color: rgba(119, 119, 119, 0.541);
border-radius: 25px;
width: 120px;
height: 120px;
margin-left: 30px;
margin-top: 30px;
}
.imgName {}
.imgPicture {
width: 60px;
height: 60px;
background-size: 100%;
vertical-align: middle;
display: inline-block;
outline: pink solid;
float none;
}
.imgPicture img {
width: 100%;
height: 100%;
outline: green solid;
}
关于为什么图片没有显示的任何想法?
【问题讨论】:
标签: javascript html css image google-cloud-firestore