为了账号安全,请及时绑定邮箱和手机立即绑定

simditor-markdown 无法监听事件

simditor-markdown 无法监听事件

大话西游666 2018-10-11 14:15:32
有没有大神遇到过 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)} />拜托了.
查看完整描述

1 回答

?
慕尼黑8549860

TA贡献1818条经验 获得超11个赞

解决方法: 覆写源码的获取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没有改变的原因,后来注意到了.


查看完整回答
反对 回复 2018-11-08
  • 1 回答
  • 0 关注
  • 530 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号