Skip to content
Advertisement

Reload saved data in editor.js using Vapor 3 backend and Leaf page

I am using a editor.js in a leaf page to allow my users to create a text document. When the user hits save editor.js ouputs what they have created as JSON and I save this to the database with the Vapor back end. This all works fine. I now want the user to be able to go back into the page and edit the content they have been creating, adding more blocks or changing exiting ones. The editor.js docs say that you simply add in the JSON to a data field when you create the editor.

This is how I am doing this. Firstly I bring the data down from the database and encode it to JSON. Then pass it to the leaf page. (Variable Name blockData)

JavaScript

It is slightly complicated as I am using a leaf tag to bring in the JSON data, and as tags don’t work inside a I first put in a div which will be hidden on the page, once i get it working.

JavaScript

As it is currently not hidden I can see the data on the page. I then use the following script to load the editor.js.

JavaScript

The problem I am having is that the editor is not loading the saved data. Any ideas?

Advertisement

Answer

I guess it works if you change

JavaScript

To:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement