simditor-markdown icon indicating copy to clipboard operation
simditor-markdown copied to clipboard

When use markdown model, the event is not work.

Open chunhei2008 opened this issue 8 years ago • 6 comments

var Simditor = require('simditor');
require('to-markdown');
require('marked');
require('../../../dist/simditor-markdown/lib/simditor-markdown.js');
export default {
  props:['content'],
  ready:function(){
    var self = this;
    var editor = new Simditor({
        textarea: $('#simditor-component-editor'),
        markdown: true,
        toolbar: ['title', 'bold', 'italic', 'underline', 'strikethrough', 'color', '|', 'ol', 'ul', 'blockquote', 'code', 'table', '|', 'link', 'image', 'hr', '|', 'indent', 'outdent', 'alignment', '|', 'markdown']
      });
      editor.setValue(self.content);
      editor.on("valuechanged", function(){
          self.content = editor.getValue();
          console.log(editor.getValue());
      });
  }
}

marddown model the event is not work, but normal model is work well

chunhei2008 avatar Jun 09 '16 00:06 chunhei2008

解决了么? 我的再markdown下事件也无法监听

l-7-l avatar Jan 05 '17 01:01 l-7-l

https://segmentfault.com/q/1010000008018253#answers-title

l-7-l avatar Jan 05 '17 13:01 l-7-l

componentWillReceiveProps 单词写错了......

l-7-l avatar Jan 06 '17 05:01 l-7-l

修改 _convert 函数,触发markdownchanged事件,然后editor 同时监听此事件

 SimditorMarkdown.prototype._convert = function() {
    var markdownText, text;
    text = this.textarea.val();
    markdownText = marked(text);
    this.editor.textarea.val(markdownText);
    this.editor.body.html(markdownText);
    this.editor.formatter.format();
    // Fix 修复事件无法问题
    this.editor.triggerHandler('markdownchanged');
    return this.editor.formatter.decorate();
  };

uerbin avatar Feb 14 '17 08:02 uerbin

这里的问题原因是 simditor-Markdown 自己也监听了 valuechanged 事件做了处理

uerbin avatar Feb 14 '17 08:02 uerbin

或者 把simditor-markdown.js 中监听 valuechanged事件去了,valuechanged时手动设置Markdown的值

uerbin avatar Feb 14 '17 08:02 uerbin