【发布时间】:2026-01-08 19:05:01
【问题描述】:
由于 JSONStore 与 Native 中的关系数据库的行为不同,我试图了解 JSONStore 以及如何在其中存储数据的最佳方式。
例如,如果我有以下来自服务器的 JSON 响应并希望存储到离线存储:
{
"CID": "1020",
"CName": "Some names",
"Documents": [
{
"DocumentID": "12987",
"FilePath": "anyPath1",
"Signatures": [
{
"Path": "signPath1"
},
{
"Path": "signPath2"
}
]
},
{
"DocumentID": "12988",
"FilePath": "anyPath2",
"Signatures": [
{
"Path": "signPath3"
},
{
"Path": "signPath4"
}
]
}
]
}
第一
我可以从其他论坛学到什么,它说线性存储它们,但我相信多次存储相同的 CID 和 DocumentID(例如)将是多余的,虽然我不知道如何存储一些(金额无法定义)签名:
var collections = {};
var collectionName = 'someName';
collections[collectionName] = {};
collections[collectionName].searchFields =
{CID: 'string', CName: 'string', DocumentID: 'string', FilePath: 'string'};
第二
或者我可以通过通常的关系数据库技术来做到这一点:
客户
var customers = {};
var customersColl = 'customers';
customers[customersColl] = {};
customers[customersColl].searchFields =
{CID: 'string', CName: 'string'};
文档
var documents = {};
var documentsColl = 'documents';
documents[documentsColl] = {};
documents[documentsColl].searchFields =
{CID: 'string', DocumentID: 'string', FilePath: 'string'};
签名
var signatures = {};
var signaturesColl = 'signatures';
signatures[signaturesColl] = {};
signatures[signaturesColl].searchFields =
{DocumentID: 'string', SignaturePath: 'string'};
当使用这种技术时,我相信很难维护数据删除。例如:
要删除某些客户,我需要在 Documents 中获取受人尊敬的客户,并在 Signatures 中删除受人尊敬的文档,并在 Documents 中删除客户,因为没有外键来“自动化”它。
请告诉我哪一种/什么是最有效的方法。
第三
来自post 的方法,我认为最好也将它们线性存储。
【问题讨论】:
标签: javascript jsonstore