本文介绍了从Firebase数据库排序列表数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
再次需要你们的帮助:-)!
again I need a bit of help from you people:-)!
我想按值完成"对* ngFor中的数据进行排序
I want to sort data in *ngFor by value "finished"
我通过以下方式获取数据:
I get my data with :
this.db.list(`/avatars/`).valueChanges().subscribe(d => {
this.avatarhall = d;
并以html格式显示,如下所示:
and show it in html like this:
<div *ngFor="let to of avatarhall; let i = index">
<ion-list>
<ion-item>
<ion-thumbnail item-start>
<img src="../assets/ghosts/{{to.avatar}}">
</ion-thumbnail>
<h1> {{to.monstername}}</h1>
<p>Finished Tasks:{{to.finished}}</p>
<ion-icon name="star" item-end>{{i +1}}</ion-icon>
</ion-item>
</ion-list>
</div>
我的管道已创建,但我不知道如何按Finished的值对其进行排序:
My pipe is created but I don't know how to sort it by the value of finished:
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'orderbytask',
})
export class OrderbytaskPipe implements PipeTransform {
transform(value: any[], args:string):any[] {
return value.sort();
}
}
实际上,这是应用程序的一部分,您可以在其中检查您在梯子上的位置
In real, this is a part of app where you can check your position on the ladder
推荐答案
您可以使用内置的javascript排序功能.
You can use javascript built in sort function.
this.db.list(`/avatars/`).valueChanges().subscribe(d => {
this.avatarhall = d.sort((a,b) => a.finished - b.finished);
您可以在中找到各种文档.mdn
这篇关于从Firebase数据库排序列表数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!