【发布时间】:2020-12-26 09:48:29
【问题描述】:
我想让我的列表按子名“name”的字母顺序排序。目前这是我用来呈现页面的服务器文件:
app.get('/testpage', function (request, response) {
var testDBref = database.ref('testdb')
testDBref.once('value', function (snapshot) {
var result = snapshot.val()
if (!result) {
result = {}
};
response.render('TestPage.ejs', {
items: result,
pageTitle: "My Lists"
});
});
});
但是,当我执行以下操作时:
app.get('/testpage2', function (request, response) {
var testDBref2 = database.ref('testdb').orderByChild('name')
testDBref2 .once('value', function (snapshot) {
snapshot.forEach(function(child){
console.log(child.val()) // NOW THE CHILDREN PRINT IN ORDER
var result = snapshot.child('name').snapshot.key
response.render('testpage2.ejs', {
items: result,
pageTitle: "My Lists"
});
});
});
});
错误提示:发送到客户端后无法设置标头,req.next 不是函数。
当我把它控制台到日志时:
app.get('/testpage2', function (request, response) {
var testDBref2 = database.ref('testdb').orderByChild('name')
testDBref2 .once('value', function (snapshot) {
snapshot.forEach(function(child){
console.log(child.val())
});
});
});
它在 json 中按字母顺序排序(当然它不会显示在网页中)。我是 nosql 数据库的新手,所以任何帮助都将不胜感激:)
【问题讨论】:
标签: node.js firebase express firebase-realtime-database nosql