我有以下数据结构:
"users": {
$userid: {
"forms": {
"ID_OF_FORM 1": { "name": "Name goes here" },
"ID_OF_FORM 2": { "name": "Name goes here" }
}
}
}
我希望能够把我的"形式"在文件夹系统中,为用户更好地组织所有这些。现在我用/users/auth.id/forms/ID
打电话给他们。我计划将对象放在forms
对象中,但我不认为如果我这样做,我只能用表单ID 来调用它们。
我无法理解如何存储这些文件夹,以便轻松显示这些文件夹。
你认为这会有用吗?有没有人有更好的建议去做这件事?
"users": {
$userid: {
"forms": {
"ID_OF_FORM 1": { "name": "Name goes here", "folder_id": "ID_OF_FOLDER" },
"ID_OF_FORM 2": { "name": "Name goes here", "folder_id": "ID_OF_FOLDER" }
},
"folders": {
"ID_OF_FOLDER 1": { "name": "name of folder" },
"ID_OF_FOLDER 2": { "name": "name of folder" },
"ID_OF_FOLDER 3": {
"name": "name of folder",
"ID_OF_FOLDER 4": { "name": "would this even work" }
}
}
}
}
答案 0 :(得分:2)
对我来说很好看,虽然很难确定除非知道所有用例(StackOverflow不是真正的论坛)。
我会将folders
改为:
"folders": {
"ID_OF_FOLDER 1": { "name": "name of folder" },
"ID_OF_FOLDER 2": { "name": "name of folder" },
"ID_OF_FOLDER 3": { "name": "name of folder" },
"ID_OF_FOLDER 4": { "name": "would this even work", "folder_id": "ID_OF_FOLDER 3" }
}
否则,您可能会超过Firebase对树的深度施加的32级限制。好消息是你可以通过它的ID直接访问任何文件夹。
您可能考虑为所有项目类型使用单个顶级节点,包括表单和文件夹(以及在构建应用程序时可能出现的任何其他内容):
"items": {
"ID_OF_FORM 1": { "type": "form", "name": "Name goes here", "folder_id": "ID_OF_FOLDER" },
"ID_OF_FORM 2": { "type": "form", "name": "Name goes here", "folder_id": "ID_OF_FOLDER" }
"ID_OF_FOLDER 1": { "type": "folder", "name": "name of folder" },
"ID_OF_FOLDER 2": { "type": "folder", "name": "name of folder" },
"ID_OF_FOLDER 3": { "type": "folder", "name": "name of folder" },
"ID_OF_FOLDER 4": { "type": "folder", "name": "would this even work", "folder_id": "ID_OF_FOLDER 3" }
}
但我认为这对您的用例目前来说并不太有益。鉴于你所说的,文件夹和表单之间的分离看起来非常好。