angular - angularfire2按子值排序列表
问题描述
我有这样的firebase db
"students" : {
"-LDD0MIigieZQ3Fcaj1Z" : {
"ContactNo" : "0752155466",
"Email" : "sdsdsd@sdsd.com",
"FirstName" : "Ishana",
"Gender" : "Female",
"LastName" : "Dahanayake",
"Password" : "1234",
"score" : 6
},
"-LDD0ceFiy2RI1avfMWA" : {
"ContactNo" : "0752155466",
"Email" : "232323@sdsd.com",
"FirstName" : "Ruwan",
"Gender" : "Male",
"LastName" : "Perera",
"Password" : "1234",
"score" : 1
}
}
我需要按分数对这些学生进行排序
我试过这样
let ref = this.afDB.list('/students',ref=>ref.orderByChild('score')).snapshotChanges()
.map(changes =>{
return changes.map(c=> ({key:c.payload.key,...c.payload.val()}));
});
return ref;
但它不会根据分数值改变顺序。我怎样才能对这些值进行排序?
解决方案
如果你写的这段代码:
let ref = this.afDB.list('/students',ref=>ref.orderByChild('score')).snapshotChanges()
.map(changes =>{
return changes.map(c=> ({key:c.payload.key,...c.payload.val()}));
});
return ref;
返回您需要排序的值,我只需添加 return ref.sort();
推荐阅读
- python - 通过 Python 拆分命令行输出
- reactjs - React 和 .Net Core Web API:Axios API 显示状态“待定”。无法获得想要的数据
- powershell - 保存 Office 365 邮箱中的电子邮件附件
- php - :SQLSTATE [HY000]:一般错误:1364 字段
- flutter - 如何在颤振中使用 googleapis 包将视频上传到 YouTube?
- bash - 使用 crontab 备份 Git Repo 的 Shell 脚本
- reactjs - 如何在 react-firestore 中使用 LIKE?
- php - 查找 [abc] 但不查找 [;;abc] 的正则表达式
- javascript - 如何根据另一个值自动将列表中的下一个字母分配到单元格中?
- c - 当我用bison解析一个java写的helloworld文件时,bison只能一行行解析。如何在多行中解析它?