typescript - 如何从离子3实时Firebase中的数据列表中删除特定数据
问题描述
我能够上传和获取数据,但我想使用一个按钮从数据列表中删除数据。下面是我的代码
ionViewDidLoad() {
console.log('ionViewDidLoad PagesAllpatientsPage');
this.ph.getPatientProfile(this.id).once('value', snapshot => {
this.patientsList = [];
console.log('sjiy')
snapshot.forEach(snap => {
this.patientsList.push({
id: snap.key,
name: snap.val().name,
age: snap.val().age,
gender: snap.val().gender,
phonenumber: snap.val().phonenumber,
});
console.log(this.patientsList)
return false
});
});
}
deletePatient(id:any,) {
firebase.database().ref(`userProfile/${this.user.uid}/PatientInfo/${id}`).remove(id)
}
我想要实现的只是通过单击按钮从 PatientInfo 中删除数据,还请提供
<button ion-button block (click)="deletePatient(id)">Delete Record</button>
解决方案
我知道这有点晚了,但它可能会帮助有需要的人。
/* this will help you get the ref of unique id of the current data */
uid = **apH....q1e2** in this case
let ref = this.afDatabase.database.ref('userProfile/' + uid + 'PatientInfo');
/* now to remove patient info */
ref.remove().then(data => {
console.log('Data removed successfully.');
})
推荐阅读
- php - 无法通过 if 语句检查查询
- java - 尝试从加密列-sql 服务器获取纯文本时,如何解决“在证书存储中找不到带有指纹 null 的证书”?
- python - 如何识别浮点变量?获取 ValueError:无法将字符串转换为浮点数:
- java - 如何在 Firebase 图像标记中使用具有 uint8 输入和输出数据类型的 TFLite 模型
- flutter - Flutter Provider 不会重建小部件
- html - 为什么文本装饰显示在我客户的手机中,但没有显示在我的手机或浏览器中?
- android - Android Studio - 具有扳手图标的属性有什么用?
- excel - 从脚本字典中粘贴项目值
- scala - 如何进一步提取列表以从双嵌套列表中创建三重嵌套列表
- php - 数组,获取顶层的标题和数据