我试图通过某个键(sid)值删除特定线程顺序的注释。
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数据库
const commentList = this.af.database.list('/eComments', {
query: {
orderByChild: 'sid',
equalTo: sid
}
});
commentList.remove();
无论如何我可以按键值删除?
答案 0 :(得分:0)
这是一种方式:
const commentList = this.af.database.list('/eComments', {
preserveSnapshot: true,
query: {
orderByChild: 'sid',
equalTo: sid
}
});
commentList.subscribe(snapshots=>{
snapshots.forEach(snapshot => {
snapshot.ref.remove();
});
})
我不是AngularFire2专家,所以可能会有更简单/更惯用的方式。