U
U
Username2019-02-13 12:58:45
JavaScript
Username, 2019-02-13 12:58:45

How to make contenteditable editor in ReactJS with text conversion back to json file?

Good afternoon!
A string comes to my input, which I parse and break into lexemes, as a result I get a two-dimensional array, where each element of the array is an object that should be in the string.
Example:

[
  // первая строка
  [
    {type: 'text', value: 'Привет'},
    {type: 'tag', value: 'get_users'},
  ],
  // вторая строка
  [
    {type: 'text', value: 'мир'},
  ],
]

What I output: I mark all tags as contenteditable="false" so they can be easily removed
5c63e86b47695594071863.pngHow it renders:
<div contenteditable="true" class="textarea">
  <div>Привет <span class="tag tag-blue" contenteditable="false">get_users</span></div>
  <div>мир</div>
</div>

Questions
  1. How can I edit a line in a json file when editing a line?
  2. If, for example, the user wants to add a text field behind the get_users tag, how do I understand this event and add a new type of text behind an object with type tag in a two-dimensional array?
To summarize: How can I learn to edit the desired object in the array and add a new one if necessary, or by line break?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question