本文介绍了如何通过某些键值 Angularfire2 remove()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试通过某个键(sid)值删除特定线程订单的评论.
I am trying to delete comments of a particular thread orderby some key(sid) value.
eComments
0b4080bb4e686f003aaa340f8ed2e2a6
cid: "0b4080bb4e686f003aaa340f8ed2e2a6"
comment: "Prison Break revolves around two brothers: one ..."
createdAt: 1487250871623
rating: 0
sid: "c088239a29827946f932f73c9a1d495a"
uid: "SFmtrI0ta5PsqYkgqZuJo2"
updatedAt: 1487250871623
4bde9de83ac2bb6d06df9876c2294483addclose
cid: "4bde9de83ac2bb6d06df9876c2294483"
comment: "arrives at the jail, he meets the prison denize..."
createdAt: 1487251466761
rating: 0
sid: "e8c2d3c2aaf877fcdf0c103229645981"
uid: "SFmtrI0ta5PsqYkgqZuJo2E"
updatedAt: 1487251466761
假设我想删除 sid: "c088239a29827946f932f73c9a1d495a"
我试过了,但不幸的是它删除了所有的 eComments 数据库
Let say I wanted to delete sid: "c088239a29827946f932f73c9a1d495a"
I tried this, but unfortunately it deletes all the eComments database
const commentList = this.af.database.list('/eComments', {
query: {
orderByChild: 'sid',
equalTo: sid
}
});
commentList.remove();
我可以按键值删除吗?
推荐答案
这是一种方式:
const commentList = this.af.database.list('/eComments', {
preserveSnapshot: true,
query: {
orderByChild: 'sid',
equalTo: sid
}
});
commentList.subscribe(snapshots=>{
snapshots.forEach(snapshot => {
snapshot.ref.remove();
});
})
我不是 AngularFire2 专家,所以可能有更简单/更惯用的方法.
I am not an AngularFire2 expert, so there might be easier/more idiomatic ways.
这篇关于如何通过某些键值 Angularfire2 remove()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!