SpecialistOff.NET / Вопросы / Статьи / Фрагменты кода / Резюме / Метки / Помощь / Файлы

Список вопросов Печать

Как в mithril.js подключить редактор кода codemirror 5?


Метки: mithril.js codemirror javascript 

Ответы

RemiZOffAlex  Создано: 2023-01-09 04:29:04.601769  Обновлено: 2023-01-09 04:29:04.601787
function PageSource() {
    let data = {
        page: null,
        editor: null,
        newLink: '',
    }
   function editor_init() {
       let vCode = document.getElementById('page_content');

        data.editor = CodeMirror(vCode, {
            value: data.page.content,
            lineNumbers: true,
            lineWrapping: true,
        });
};
    return {
        onupdate(vnode) {
            console.log('PageSource.onupdate');
            console.log(vnode);
            if (data.page!=null) {
                if (data.editor==null) {
                    console.log(data.page);
                    editor_init();
                }
            }
        },
        view: function(vnode) {
            let result = [];
            if (data.page!=null) {
                result.push([
                    m('div', {class: 'form-group mb-2'}, [
                        m('label', {class: 'form-label'}, 'Текст'),
                      m('div', {id: 'page_content'})
                    ]),
                ]);
            };
            return result
        }
  };
};

Возможно будут интересны и другие вопросы