【发布时间】:2017-07-06 19:21:40
【问题描述】:
从 addChildEventListener 调用以下函数,以便在需要时从我的 Firebase 数据库中删除特定节点。 这里的问题是该函数启动了“删除的项目”。 toast,表示任务已成功执行,但该节点在数据库中仍然存在。
谁能告诉我怎么回事?
private void showData(DataSnapshot ds) {
String keyValue = null;
if(ds.hasChildren()) {
keyValue = ds.getKey();
Toast.makeText(getActivity().getApplicationContext(), "Removing item...", Toast.LENGTH_SHORT).show();
ds.getRef().child(keyValue).removeValue().addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Toast.makeText(getActivity().getApplicationContext(), "Item removed.", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getActivity().getApplicationContext(), "Something bad happened while removing item.", Toast.LENGTH_SHORT).show();
}
}
});
}
}
编辑 如果有帮助,我的查询如下:
orderItemsByTime = db.getInstance().getReference().child("items").orderByChild("time");
【问题讨论】:
-
当你
addOnCompleteListener时你有没有试过删除.getRef()? -
做到了。不幸的是,没有奏效。
标签: javascript android firebase firebase-realtime-database