simditor-markdown
simditor-markdown copied to clipboard
When use markdown model, the event is not work.
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
解决了么? 我的再markdown下事件也无法监听
https://segmentfault.com/q/1010000008018253#answers-title
componentWillReceiveProps 单词写错了......
修改 _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();
};
这里的问题原因是 simditor-Markdown 自己也监听了 valuechanged 事件做了处理
或者 把simditor-markdown.js 中监听 valuechanged事件去了,valuechanged时手动设置Markdown的值