【发布时间】:2016-09-21 11:47:14
【问题描述】:
router.get('/getAllMeals',function(req,res){
var allMeals = [];
allMeals.push("foo");
mealsRef.on("value",function(dataSnapShot){
dataSnapShot.forEach(function(child){
console.log(child.val());
var oneMeal = child.val();
allMeals.push(oneMeal);
});
});
allMeals.forEach(function(obj){
console.log(obj);
});
res.send(allMeals);
}); //RETRIEVE ALL
在上面的代码中,我无法将作为有效 JSON 对象的 oneMeal 添加到我创建的 allMeals 数组中。 console.log 的结果只显示“foo”,长度也是 1。
【问题讨论】:
-
我为您的代码提交了一个修复程序,您知道还有一个额外的
});吗?
标签: javascript node.js firebase-realtime-database