【发布时间】:2019-07-23 08:12:42
【问题描述】:
我正在尝试获取具有特定 ID 的帖子的所有评论。我已经尝试了所有的解决方案,但它从来没有奏效。当我尝试获取“帖子”(第一级节点)时,相同的方法有效,但嵌套级别不起作用
calculate_post_rating(post_id){
console.log('this post id: '+post_id);
let dbref = firebase.database().ref('/user-reviews/'+ post_id + '/');
dbref.on('child_added', function (data){
console.log(data.key); //console is not even printing this, seems like this part is not even executed.
console.log('rated by user: ' + data.val().rating);
});
【问题讨论】:
-
您确定您传递的 post_id 正确且确实存在吗?
-
乍一看,代码看起来是正确的。查看应用程序的日志记录输出是否有任何错误。如果这没有帮助,请查看是否可以在 jsbin 或 stackblitz 等工具中重现问题(使用或不使用 Ionic),以便我们查看它。
标签: javascript firebase ionic-framework firebase-realtime-database ionic2