javascript - bootstrap 3-所见即所得编辑器对象始终未定义

标签 javascript twitter-bootstrap-3 wysihtml5

我使用这个富文本:https://github.com/bootstrap-wysiwyg/bootstrap3-wysiwyg

它工作正常,但我需要获取 wysihtml5 编辑器对象来运行一些命令

doc说我可以使用以下代码获取 wysihtml5 编辑器对象:

var wysihtml5Editor = $('#some-textarea').data("wysihtml5").editor;
wysihtml5Editor.composer.commands.exec("bold");

但是 wysihtml5Editor 完全未定义

记录 $('#some-textarea').data("wysihtml5") 打印此内容:

Wysihtml5 {el: n.fn.init[1], toolbar: n.fn.init[1], editor:undefined}

如何获取编辑器对象?

最佳答案

我自己找到了答案,但无论如何还是感谢 Daemedeor 和 DA。!

在 bootstrap3-wysihtml5.js 中 createEditor 方法没有返回,所以

this.editor =  this.createEditor(toolbarOpts);

this.editor 未定义

我像这样添加返回

  createEditor: function(options) {
    options = options || {};

    // Add the toolbar to a clone of the options object so multiple instances
    // of the WYISYWG don't break because 'toolbar' is already defined
    options = $.extend(true, {}, options);
    options.toolbar = this.toolbar[0];

    return this.initializeEditor(this.el[0], options);
  }

一切都好!

关于javascript - bootstrap 3-所见即所得编辑器对象始终未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31016428/

相关文章:

javascript - 我可以访问 web worker 上的文档 cookie 吗

javascript - ResponsiveVoice 被 CORS 屏蔽

javascript - Wysihtml5和iframe视频的问题

javascript - 在 wysiHTML5 编辑器中以编程方式插入 HTML

javascript - 当 div 增长时自动向下滚动浏览器窗口

javascript - ASP.NET JavaScript 斜杠符号转义

css - 如何使文本与较大的图标垂直居中?

javascript - 单击元素时 Bootstrap 下拉菜单不会关闭

javascript - 使用数据属性的 Bootstrap 词缀仅适用于页面重新加载