【发布时间】:2019-10-06 16:20:40
【问题描述】:
我需要将我的练习集的数据显示到 HTML 表格中。 我想通过使用 getElementByID 来完成它,但它只显示 1 行。这样做的正确方法是什么?谢谢。
请看下面的代码:
HTML 代码
<div class="container">
<h2>Manage Exercises:</h2>
<table class="table table-striped">
<thead>
<tr>
<th>Exercise Name</th>
<th>Body Part</th>
<th>Exercise Type</th>
<th>Sets + Reps/Duration</th>
<th>Image</th>
</tr>
</thead>
<tbody>
<tr id="tr">
<td id="ename"></td>
<td id="body_part"></td>
<td id="etype"></td>
<td id="esets"></td>
<td id="eimage"></td>
</tr>
</tbody>
</table>
JavaScript 代码:
console.log("Initialisation Successful!");
var db = firebase.firestore();
var exRef = db.collection('Exercises');
var allex = exRef
.get()
.then(snapshot => {
snapshot.forEach(doc => {
var EName = doc.data().Name;
var Type = doc.data().Type;
var BodyPart = doc.data(). BodyPart;
var Sets = doc.data().Sets;
const Image = doc.data().Image;
document.getElementById("ename").value = EName;
});
})
.catch(err => {
console.log('Error getting documents', err);
});
更新:
替换为:document.getElementById("ename").value = EName;
作者:document.getElementById("ename").innerText = EName;
现在只显示一条记录,如何显示全部?
【问题讨论】:
-
只有像
<input>这样的表单控件有value属性
标签: javascript firebase html-table google-cloud-firestore