[英]how can i sort firebase timestamp data reverse reactjs
When I create new note, it orders old to new, but I want to order new to old (reverse it).当我创建新笔记时,它从旧到新排序,但我想从新到旧排序(反转它)。 How can i do this ?
我怎样才能做到这一点 ?
my codes:我的代码:
const notesRef = useFirestore().collection('users').doc(uid).collection("notes");
const {status, data} = useFirestoreCollection(notesRef.orderBy("timezone"));
and its image: (Here, it order like 1-2-3, but i want to order, 3-2-1, new to old)和它的形象:(在这里,它的顺序像 1-2-3,但我想点,3-2-1,从新到旧)
our return like map:我们的回报就像地图:
{data?.docs?.map((d, index) => {
return (<Note
key={index}
id={index}
title={d.data().title}
content={d.data().content}
onDelete={deleteNote}
onDocId={d.id}
timezone={d.data().timezone}
/>);
})}
There are a bunch of ways of doing this.有很多方法可以做到这一点。
notesRef.orderBy("timezone").limitToLast(25);
const {status, data} = useFirestoreCollection(notesRef.orderBy("timezone"));
console.log(data.docs.reverse())
To sort a query in descending order, you can pass a second parameter to orderBy
.要按降序对查询进行排序,您可以将第二个参数传递给
orderBy
。 So:所以:
notesRef.orderBy("timezone", "desc")
Also see the Firebase documentation on ordering data .另请参阅有关订购数据的 Firebase 文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.