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
在上面的代码中,我无法将oneMeal这是一个有效的JSON对象添加到我创建的allMeals数组中。 console.log的结果只显示“foo”并且长度为1.Javascript列表对象无法添加JSON? Node.JS,Firebase
我为您的代码提交了一个修复程序,您知道有一个额外的'});'? – jrbedard