【发布时间】:2016-11-16 15:58:43
【问题描述】:
代码:
app.controller('ctrl', function ($scope, $firebaseArray, $timeout) {
$scope.data = [];
var _start = 0;
var _end = 4;
var _n = 5;
console.log("1");
$scope.getDataset = function() {
console.log("4");
fb.orderByChild('time').startAt(_start).endAt(_end).limitToLast(_n).on("value", function(dataSnapshot) {
console.log("5");
$scope.data.push(dataSnapshot.val());
console.log("THE VALUE:"+dataSnapshot.val());
console.log("6");
});
console.log("7");
_start = _start + _n;
_end = _end + _n;
console.log("8");
};
console.log("2");
$scope.getDataset()
console.log("3");
});
数据库:
"posts" {
"fun" {
"-Kzugwouzgafsdbkuzbf" {
"time": 1478443829263
}
"-Krugwouzgafawdrawdr" {
"time": 1478446164691
}
}
}
问题:
为什么我的dataSnapshot.val() 等于null?
注意:
我想按时间戳排序帖子并查询最近的 5 个。
【问题讨论】:
-
请包含重现问题所需的最少、完整信息(JSON + 代码)。因此,您查询的实际数据以及带有
_start、_end和_n的硬编码值的查询。 -
@FrankvanPuffelen 完成。
-
谢谢。现在还请提供所需的最小实际 JSON。最后:你如何确定
snapshot.val()是null?您共享的代码中没有任何内容显示其价值。 -
完成。至于JSON,我会更新数据库文本。
-
@FrankvanPuffelen 现在全部完成 :)
标签: javascript angularjs firebase firebase-realtime-database angularfire