我有一个根节点的两个节点,我想在一个请求中删除两个节点的数据。两个子节点具有相同的 key 。我试过这个:
Firebase firebaseRef = new Firebase(<root_path>);
Map<String, Object> childUpdates = new HashMap<>();
childUpdates.put(<path_to_first_node>, key);
childUpdates.put(<path_to_second_node>, key);
listToRemoveRef.updateChildren(childUpdates, null);
但它只删除了第一个节点的数据
最佳答案
您似乎错误地使用了 updateChildren
函数。你要做的是这个
Firebase firebaseRef = new Firebase(<root_path>);
Map<String, Object> childUpdates = new HashMap<>();
childUpdates.put("<path_to_first_node>" + key, null);
childUpdates.put("<path_to_second_node>" + key, null);
listToRemoveRef.updateChildren(childUpdates);
updateChildren
的第二个参数没有将值设置为 null
,它是一个可选的完成监听器 (see documentation)。因此,与其在最后一行将 null
传递给它,不如将其省略。
关于android - 如何在 firebase 的一个请求中删除多个节点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37553179/