simditor-markdown 无法监听事件

有没有大神遇到过 tower的开源编辑器simditor使用了 simditor-markdown 扩展就无法监听事件了

react, jsx:

    componentDidMount () {
      this.initEditor()
    }
    
    initEditor = () => {
      this.editor = new Simditor({
        textarea: this.textArea,
        markdown: true,
        toolbar: ['title', 'bold', 'italic', 'underline', 'code', 'blockquote', '|', 'ol', 'ul', '|', 'markdown']
      })
      this.editor.setValue(marked(this.props.content))
      this.editor.on('valuechanged', (e, src) => {
       this.props.onTextChange(toMarkdown(this.editor.getValue()))
      })
    }

Tag:

  <textarea ref={textarea => (this.textArea = textarea)} />
拜托了.
阅读 3.8k
1 个回答

解决方法: 覆写源码的获取value, 包装标签方法(继续didMount下):

    const editorNote = this
    simditorMarkdown.prototype._convert = function () {
      const text = this.textarea.val();
      editorNote.props.onTextChange(text)
      const markdownText = marked(text);
      // textarea
      this.editor.textarea.val(markdownText);
      // tag
      this.editor.body.html(markdownText);
      // 包了层div
      this.editor.formatter.format();
      return this.editor.formatter.decorate();
    };
    this.editor.setValue(marked(this.props.content))  

另外分享下: 表单组件建议用onchange,今天有个上传组件手贱写成了onClick, 刚开始以为state没有改变的原因,后来注意到了.

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题