我一直在关注本教程:http://mariechatfield.com/tutorials/firebase/step5.html
但我想让它变得有趣,我不想打印最后一个数据库对象,而是打印所有对象。
我尝试打印数据库,效果很好。我只需要编辑 Html。我尝试使用换行符,但也没有。它不断附加到起始字符串,而不是创建新行/容器。
recommendations.limitToLast(10).on('child_added', function(childSnapshot) {
// Get the recommendation data from the most recent snapshot of data
// added to the recommendations list in Firebase
recommendation = childSnapshot.val();
console.log(recommendation);
// Update the HTML to display the recommendation text
$("#title").append(recommendation.title)
$("#presenter").append(recommendation.presenter)
$("#link").append(recommendation.link)
var x = '\n';
x;
// Make the link actually work and direct to the URL provided
$("#link").attr("href", recommendation.link)
});
我希望能够为每个数据库元素拥有一个单独的容器。
最佳答案
根据请求,发布评论作为答案:
干得好!您需要做的唯一更改就是更改 \n
至<br>
。 HTML 删除空格(如换行符)。因此,要复制该换行符,您必须使用 HTML BR 元素。当然,您还需要将其附加到现有的 HTML 中。
关于Javascript 方式创建多个 HTML 容器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54280761/