Editor.js: How to update the data property of Editorjs options

Created on 25 May 2019  路  4Comments  路  Source: codex-team/editor.js

Hi,
I am not able to find any api or function in the docs which can be used to update the data.
Suppose I have updated data, and want to update the editorjs instance, I suppose something like this should be present.
editorJsInstance.setData(newData);
Can you please help in the same?

Glad to give more insight if required

Most helpful comment

render() expects to full structure object to be passed, not only blocks array.
{
"time" : 1550476186479,
"blocks" : [ {...}, {...}, {...}],
"version" : "2.8.1"
}
Its not clear from docs) You can only pass {blocks[ your_blocks ]}, it works.

All 4 comments

Hi @vsvanshi

You can use render() and clear() methods to manipulate the data

Docs: https://editorjs.io/blocks

@gohabereg
I call the render() with a very simple new set of data.

[{"type":"header","data":{"text":"Register now!","level":2}}]

I get the following error (I tried both the api.blocks.render() as well as the api.render(), but both give the stated error.):

Unhandled Rejection (TypeError): Cannot read property 'map' of undefined

The clear()' does empty the entire content. But iterating over the array of new data, and using theinsert()` gives a different error message.

Unhandled Rejection (TypeError): Cannot read property 'config' of undefined

To elaborate a bit more, I use it as a editor for a website configuration. Their is a possibility of multilanguage, so when you switch the language in the configuration, I want to replace the entire content, based on language.

I wrapped everything myself to use it in React. I now solved the issue by building in a 10ms delay. So after i change the language, I start a 'refresh' hidding the entire editor, and after 10ms the new editor for a different language is shown. This solves my issue, for now.

render() expects to full structure object to be passed, not only blocks array.
{
"time" : 1550476186479,
"blocks" : [ {...}, {...}, {...}],
"version" : "2.8.1"
}
Its not clear from docs) You can only pass {blocks[ your_blocks ]}, it works.

Resolved

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  4Comments

Yakumo-Yukari picture Yakumo-Yukari  路  5Comments

natterstefan picture natterstefan  路  5Comments

ar53n picture ar53n  路  3Comments

sei-jdshimkoski picture sei-jdshimkoski  路  5Comments