我对QuillEditor(我有多个编辑)以下,脚本:
var editors = {};
function editors() {
var toolbarOptions = [
[{'list': 'ordered'}, {'list': 'bullet'}],
];
data.forEach(function (el) {
editors[el] = new Quill(el['editor'], {modules: {toolbar: toolbarOptions}, theme: 'snow', scrollingContainer:el['quill'] });
editors[el].on('text-change', copyText(el['text'], editors[el]));
});
}
}
function copyText(text, editor) {
text.innerHTML = editor.root.innerHTML;
console.log(text.innerHTML)
}
要在后端使用它,我复制从编辑到一个文本copyText(el['text']
文本。
我需要一直工作,但在执行功能时,它应对的text / html,只有一次。我期待编辑[EL]。对(“文本的变化”,就像一个事件监听工作。
该scrollingContainer
,不滚动。我检查目标的存在,是编辑的父。
我不知道,如果这种错误一部分,但你}
功能后之后有一个额外的editors
。
这里的主要问题是,而不是设置事件侦听器正在运行的就是为什么它是只有一次运行事件侦听器。
所以改变事件监听线路:
editors[el].on('text-change', function () {
copyText(el['text'], editors[el]);
});
我一般不喜欢创造等功能功能,尤其是内循环,所以我会建议创建一个函数工厂函数,将创建的每个元素的新功能。
function createListener(text, editor) {
return function(){
copyText(text, editor);
};
}
而这样称呼它:
editors[el].on('text-change', createListener(el['text'], editors[el]));