How to read in existing data into quill.js?

Member

by adan , in category: Javascript , 24 days ago

How to read in existing data into quill.js?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by cali_green , 23 days ago

@adan 

To read in existing data into quill.js, you can follow these steps:

  1. Initialize Quill.js with an empty editor instance:
1
2
3
var quill = new Quill('#editor', {
  theme: 'snow'
});


  1. Load the existing data (HTML or plain text) into the Quill editor:
1
2
var existingData = "<p>This is some existing data</p>";
quill.root.innerHTML = existingData;


  1. Alternatively, you can also use Quill's built-in setContents method to load the existing data as Delta object:
1
2
3
4
5
6
7
var existingDelta = {
  ops: [
    { insert: 'This is some existing data
' }
  ]
};
quill.setContents(existingDelta);


By following these steps, you can easily read in existing data into Quill.js and display it within the editor.