2017-02-16 16 views
0

我想刪除某些特定的線索orderby一些鍵(sid)值的評論。如何Angularfire2刪除()的某些關鍵值

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

這是一種方式:

const commentList = this.af.database.list('/eComments', { 
     preserveSnapshot: true, 
     query: { 
     orderByChild: 'sid', 
     equalTo: sid 
     } 
    }); 
commentList.subscribe(snapshots=>{ 
    snapshots.forEach(snapshot => { 
     snapshot.ref.remove(); 
    }); 
}) 

我不是AngularFire2專家,所以有可能會更容易/更地道的方式。

+0

工作正常!謝謝。 –

+0

我用幾乎相同的方式顯示。但是,一旦我用這種方式刪除,我無法再添加相同的項目。 :|沒有得到什麼正確的做錯了:( – webcoder