猿问

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)} />
拜托了.


大话西游666
浏览 531回答 1
1回答

慕尼黑8549860

解决方法: 覆写源码的获取value, 包装标签方法(继续didMount下):&nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;editorNote&nbsp;=&nbsp;this &nbsp;&nbsp;&nbsp;&nbsp;simditorMarkdown.prototype._convert&nbsp;=&nbsp;function&nbsp;()&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;text&nbsp;=&nbsp;this.textarea.val(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;editorNote.props.onTextChange(text) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;markdownText&nbsp;=&nbsp;marked(text);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;textarea &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.editor.textarea.val(markdownText);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;tag &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.editor.body.html(markdownText);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;包了层div &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.editor.formatter.format();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;this.editor.formatter.decorate(); &nbsp;&nbsp;&nbsp;&nbsp;};&nbsp;&nbsp;&nbsp;&nbsp;this.editor.setValue(marked(this.props.content))另外分享下: 表单组件建议用onchange,今天有个上传组件手贱写成了onClick, 刚开始以为state没有改变的原因,后来注意到了.
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答