Angular 4 Firebase angularfire Sorting a list by value

前端 未结 1 1388
故里飘歌
故里飘歌 2021-01-24 08:54

I am using Angular 4 Firebase and AngularFire and i have the following firebase database

\"users\" : {
    \"Test1\" : {
      \"totalscore\" : 50,
      \"user         


        
相关标签:
1条回答
  • 2021-01-24 09:14

    The orderByValue is used when you have a data structure like this:

    "userscores" : {
        "Test1" : 50,
        "Test2" : 30,
        "Test3" : 20
        "Test4" : 10,
    }
    

    In the above you want to order the results of your query on userscores on the value of each child node.

    In your case, the value you want to sort on is in a child property totalscore under users. So you should use orderByChild:

    this.topusers = db.list('users', {
        query: {
         orderByChild: "totalscore",
         limitToFirst: 10,
        }
    });
    
    0 讨论(0)
提交回复
热议问题