我要按yDS1a41FxzZlTjVvzxjteKSHSn22排序的实际列表:
yDS1a41FxzZlTjVvzxjteKSHSn22: 1571361291153
id: "t4ImLnwtFU5e7VKcCmm4"
photoUrl: "https://firebasestorage.googleapis.*"
startDate: "2019-10-17"
unread: []
userId: "FxttC8c66QXMElHIkBFApVVGevy1"
我有一个使用Cloud Firestore作为后端的聊天应用程序。我在聊天应用程序上使用了动态属性,因此无法在Firestore查询中进行排序,一旦从Firestore中提取数据并将其存储在数组中,就必须执行此操作。问题在于,一旦我将数据存储在数组中,它就不会按时间降序排序。
qry
.onSnapshot((val) => {
val.forEach(snp => {
if (snap.data().likes.includes(snp.id)) {
this.users.push({
id: snp.id,
userId: snp.data().userId,
unread: snap.data().unread,
[this.loggedInUser.uid]: snp.data()[this.loggedInUser.uid],
});
console.log('log', this.users);
}
// remove any unique items
this.users = Array.from(new Set(this.users.map(a => a.id)))
.map(id => {
return this.users.find(a => a.id === id);
});
});
this.getPhotoUrl();
this.checkIfUnread();
let test = this.users.sort((a, b) => (a[this.loggedInUser.uid] < b[this.loggedInUser.uid]) ? 1 : -1);
});
因此,如果您发送一条消息并返回到主消息屏幕,则应按最后发送的消息对消息进行排序...这将忽略所有排序。