【发布时间】:2020-03-25 16:32:17
【问题描述】:
我正在 Ionic 3 上开发一个移动应用程序。 我在 firebase 数据库上有一个通知对象。我正在以这种方式推送一条记录的数据:
fireNots = firebase.database().ref('/notifications');
addNotification(notReq: INotReq){
this.fireNots.child(notReq.RecipientUId).push({
Title: notReq.Title,
Body: notReq.Body
}).then(() => {
resolve({ success: true });
})
}
这是 INotReq:
export interface INotReq{
RecipientUId: string,
Title: string,
Body: string
}
我在 Firebase 上的数据结构:
- 通知
- Q6cQqz0OVRPCq17OWb (RecipientUId)
- LtH7QZlWVUcIpNqb-O9
- 正文:“你有一个通知。”
- 标题:“通知标题”
现在我需要推送通知列表(notReqs: INotReq[])。
我应该使用这样的for循环吗?
addMultipleNotification(notificationRequestArray: INotReq[]){
notificationRequestArray.forEach(notificationRequest => {
this.addNotification(notificationRequest);
});
}
这是一个不好的做法吗? 或者有更好的方法吗?
【问题讨论】:
标签: typescript firebase firebase-realtime-database ionic3