我在根据参数排序数据时遇到问题。下面是代码 fragment 。
event_date 是一个时间戳
db.collection("abc")
.doc("Events")
.collection("List")
.where("event_status", "==", "0")
.orderBy("event_date", "desc").get()
.then(function (querySnapshot) {-------------------});
抛出的错误消息是,
Uncaught Error: Objects are not valid as a React child (found: Sun Nov 25 2018 17:27:56 GMT+0530 (India Standard Time)). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. Check the render method of Table.
最佳答案
默认情况下,Firebase 查询会按文档 ID 的升序检索所有文档。
您可以使用 orderBy()
指定数据的排序顺序。
在您的情况下 .orderBy("event_date", "desc")
,如果您使用 firebase serverTimestamp() 设置字段“event_date”
例如: .set({event_date = firebase.firestore.FieldValue.serverTimestamp() })
您会收到上述错误。
为了解决这个问题,您可以将其设置为 new Date()
例如: .set({event_date = new Date() })
在 Firebase 中,firebase.firestore.FieldValue.serverTimestamp()
和 new Date()
都会生成时间戳
希望这有帮助。
关于javascript - 如何根据firestore中的参数排序数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53338722/