Firestore + AngularFire2 pagination ( query items by range - .startAfter(lastVisible) )

后端 未结 3 446
借酒劲吻你
借酒劲吻你 2020-12-09 13:56

In a component I want to pull a range of items from FireStore, for ex. from 0 to 5, from 5 to 10 etc. I found this in FireStore\'s docs, but they dont use AngularFire2 so as

3条回答
  •  误落风尘
    2020-12-09 14:12

    I don't know about FireBase, but I'am awesome when you ask about all the items and then filtered.

    If you make a method that has as arguments, page and size and an array lastScore I supouse that you can make some like (NOTE: I have NOT Firestone and, the most probably, I'm wrong and the code is bad)

    //In service
    
    lastScores:number[]=[];
    lastPage:number=0; //use to know where you reach the last page
    getNextHightScores(page:number,count:number)
    {
        //get the limit
        let last=page>0?lastScores[page-1]:999999999   //if page=0 a bigger score
        //use where and limit
        return afs.collection('scores', r =>  
                r.where("score", "<", last).orderBy("score","desc").limit(count)
                .valueChanges()
                .do(r=>{  //using do to store the lastScore
                   if (r.length)
                       this.lastScore[page]=r[r.length-1].score;
                   if (r.length{console.log(r)})
    }
    //and 
    
    

提交回复
热议问题