简体   繁体   English

使用 sharedb 和 json0-ot-type 向 JSON-Object 添加键(路径)

[英]Adding a key(Path) to JSON-Object with sharedb and json0-ot-type

I am currently working with sharedb ( https://share.github.io/sharedb/ ) and the operationel transformation type json0 ( https://github.com/ottypes/json0 ).我目前正在使用 sharedb ( https://share.github.io/sharedb/ ) 和操作转换类型 json0 ( Z5E056C500A1C4B6A7110B50D807 /json05Z )://。 I need to add a key (path) to a JSON object afterwards, which should be shared via sharedb.之后我需要向 JSON object 添加一个密钥(路径),它应该通过 sharedb 共享。

For example, the key "key2" should be added to the following JSON object:例如,应将键“key2”添加到以下 JSON object 中:

{
   key1: 'some_value',
}

Unfortunately, according to the documentation of json0 ( https://github.com/ottypes/json0 ), there is no operation for this, which surprises me a lot.不幸的是,根据json0的文档( https://github.com/ottypes/json0 ),没有对此进行操作,这让我很惊讶。 How can I add a new key that will be recognized by sharedb?如何添加将由 sharedb 识别的新密钥? Simply adding the key (path) locally makes sharedb not recognize it!只需在本地添加密钥(路径),sharedb 就无法识别它!

The docs you shared say:您共享的文档说:

{p:[path,key], oi:obj} inserts the object obj into the object at [path] with key key . {p:[path,key], oi:obj}将 object obj插入到[path]处的 object 中,键为key

So you'd want to use that oi ("object insert") op shape:所以你想使用那个oi (“对象插入”)操作形状:

const op = [{p: ['key2'], oi: 'some_other_value'}]
doc.submitOp(op)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM