我的 firebase 数据库结构如下:
我要删除类别1 ,但是当我向 *.firebaseio.com/categories/1.json
发送 DELETE 请求时,我得到:
我想更改数组中的剩余索引以获得没有空项的数组。 在删除 categories[1]
后是否有可能得到这样的新数组?:
请您参考如下方法:
在这种情况下,你应该将你的项目推送到 firebase,firebase 会在时间戳后分配一个唯一的 id
来自指南:
获取由 push() 生成的唯一 ID
调用 push() 将返回对新数据路径的引用,您可以使用它来获取其 ID 的值或为其设置数据。以下代码将生成与上述示例相同的数据,但现在我们可以访问生成的唯一推送 ID
// Generate a reference to a new location and add some data using push()
var newPostRef = postsRef.push({
author: "gracehop",
title: "Announcing COBOL, a New Programming Language"
});
// Get the unique ID generated by push() by accessing its key
var postID = newPostRef.key;