【发布时间】:2018-02-21 15:30:56
【问题描述】:
我正在处理 angular 4 项目,我在其中使用智能表。对于数据库,我使用的是 firebase。 我写了一个函数来删除它从火力库中删除的行数据,但其他数据显示两次(重复)。 以下是代码
我在服务中有写函数来获取如下数据
getEData()
{
return this.af.list('/enquirydata').snapshotChanges().map(changes => {
return changes.map(c => ({ key: c.payload.key, ...c.payload.val() }));
});
}
也为了删除我在服务中写了以下函数
deleteEnquiry(data){
this.af.list(`/enquirydata`).remove(data);
console.log("item deleted");
}
现在在component.ts中我写了如下
source: LocalDataSource = new LocalDataSource();
items: Array<any> = [];
constructor(private service: SmartTableService, private router: Router) {
this.service.getEData().subscribe(k=> {
k.map(c=> {
this.items.push(c);
this.source.load(this.items);
})
});
}
onDelete(event) {
console.log(event);
if (window.confirm('Are you sure you want to delete?')) {
this.service.deleteEnquiry(event.data.key);
} else {
event.confirm.reject();
}
}
有什么帮助吗?
【问题讨论】:
-
您正在将值推送到数组中。
this.items.push(c);。首先通过'this.array = []'清除数组 -
它不工作,请您提供解决方案
标签: angular typescript firebase firebase-realtime-database ng2-smart-table