【发布时间】:2018-06-20 21:16:08
【问题描述】:
我有一个post 的列表,我正在使用.on('child_added') 获取它们,问题是我只想在添加项目时获得post 的而不是当它被删除,然而,似乎.on('child_added') 被调用,即使是在一个帖子被删除时。这不是我需要的。
这是我的功能:
if(fromClick) { this.subscription.off(); this.firstRun = true;}
this.postFeed = new Array();
this.subscription = this.database.database.ref('/posts/'+this.locationId)
.orderByChild('created')
.limitToLast(10);
this.subscription.on('child_added', (snapshot) => {
this.postFeed.push(snapshot.val());
});
所以它显示最后一个10,然后当添加一个项目时,它也会将其添加到数组中,但是当一个项目被删除时,它会再次被调用..
如何防止这种情况发生?这样调用只发生在添加的post 上?
【问题讨论】:
标签: javascript angular firebase firebase-realtime-database