简体   繁体   中英

How to load the latest posts with score above 100?

SITUATION:

I currently load the latest posts chronologically with this code:


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();

QUESTION:

How should I modify it to essentially have the exact same behaviour but to only query posts with scores above 100 according to their chronological order ?


UPDATE:

I have finally found a way to use the "create another index" method with my architecture. But one hurdle remains:

How to copy a childNode from one node to another?

I rethought my architecture and created a specific index for top posts:

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});
   }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM