gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 19:09:23 24 4
gpt4 key购买 nike

我使用这个富文本: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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com