状况:
我目前按时间顺序使用以下代码加载最新帖子:
CODE:
$scope.data = [];
var _n = Math.ceil(($(window).height() - 50) / (350)) + 1;
var _start = <%= lastID %>;
var firstElementsLoaded = false;
$scope.getDataset = function() {
fb.orderByChild('id').startAt(_start).limitToFirst(_n).on("child_added", function(dataSnapshot) {
_start = dataSnapshot.child("id").val() + 1;
console.log("LAST TRUE ID:"+ _start);
$scope.data.push(dataSnapshot.val());
$scope.$apply()
console.log("THE VALUE:"+$scope.data);
firstElementsLoaded = true;
});
};
$scope.getDataset();
问题:
我应该如何修改它以基本上具有完全相同的行为,但只根据其时间顺序查询得分高于100的帖子?
更新
我终于找到了一种方法来使用我的架构“创建另一个索引”方法。但仍存在一个障碍:
答案 0 :(得分:3)
我重新思考了我的架构并为热门帖子创建了一个特定的索引:
if (funPost.score >= global.hotNumber && funPost.hot == false) {
var hotPostRef = firebase.database().ref("hot/section/"+key);
var hotPost = {
title: funPost.title,
image: funPost.image,
id: funPost.id,
key: funPost.key
}
hotPostRef.set(hotPost);
funPostRef.update({"hot": true});
}
else if (funPost.score <= (global.hotNumber - 25) && funPost.hot == true) {
var hotPostRef = firebase.database().ref("hot/section/"+key);
hotPostRef.remove();
funPostRef.update({"hot": false});
}