本文介紹了卡在按值/子鍵刪除父推送鍵的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我想按值/子鍵刪除父按鍵:
I want to delete a parent pushed key by value/childkey:
export class FaqsPage {
qS: Observable<any[]>;
ques = '';
ans = '';
constructor(private db: AngularFireDatabase) {}
ionViewDidLoad() { this.qS = this.db.list('table/faq').valueChanges(); }
removeItem(id){this.db.list('table/faq').remove(id);}
removeItem() 刪除所有按鍵.難怪,因為我無法獲得父密鑰
removeItem() deleting the whole all pushed keys. No wonder because i couldn't get the parent key
//faq.html
<ion-list>
<ion-item-sliding *ngFor="let el of qS | async">
<ion-item>
<b>{{ el.Q }}</b><br>{{ el.A }}
</ion-item>
<ion-item-options side="right">
<button ion-button color="red" icon-only (click)="removeItem(el.key)"><ion-icon name="trash"></ion-icon></button>
</ion-item-options>
</ion-item-sliding>
</ion-list>
由于 valueChanges()
el.key doesn't get the the key (e.g. Kzwv8d_i-0QZuf2NT8Z) because of valueChanges() and i have no idea how to do it within current iteration.
推薦答案
希望你用的是angularfire2
I hope you are using angularfire2
this.qS = this.db.list('table/faq').snapshotChanges().map(changes => {
return changes.map(c => ({ key: c.payload.key, ...c.payload.val() }));
});
這將返回帶有鍵的 qS
這篇關于卡在按值/子鍵刪除父推送鍵的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!