【问题标题】:Is it possible to change tinyMCE custom Toolbar ListBox values after tinymce init是否可以在 tinymce 初始化后更改 tinyMCE 自定义工具栏列表框值
【发布时间】:2017-07-28 02:21:41
【问题描述】:

下面的例子是向 tinyMCE 添加自定义下拉菜单,是否可以在 init tinyMCE 后再次更改?例如,在初始化 tinyMCE 后,通过不同列表的另一个按钮再次更新列表。 https://codepen.io/tinymce/pen/JYwJVr

tinymce.init({
  selector: 'textarea',
  height: 500,
  toolbar: 'mybutton',
  menubar: false,
    content_css: [
    '//fonts.googleapis.com/css?family=Lato:300,300i,400,400i',
    '//www.tinymce.com/css/codepen.min.css'],

  setup: function (editor) {
    editor.addButton('mybutton', {
      type: 'listbox',
      text: 'My listbox',
      icon: false,
      onselect: function (e) {
        editor.insertContent(this.value());
      },
      values: [
        { text: 'Menu item 1', value: '&nbsp;<strong>Some bold text!</strong>' },
        { text: 'Menu item 2', value: '&nbsp;<em>Some italic text!</em>' },
        { text: 'Menu item 3', value: '&nbsp;Some plain text ...' }
      ],
      onPostRender: function () {
        // Select the second item by default
        this.value('&nbsp;<em>Some italic text!</em>');
      }
    });
  }
});

【问题讨论】:

    标签: tinymce tinymce-4


    【解决方案1】:

    我没有找到任何只能为自定义下拉菜单更新的选项。这不是什么好方法,但我可以使它工作的唯一方法。所以我所做的就是删除 tinymce 并重新添加它。

    tinymce.remove();
    tinymce.init({
     selector: 'textarea',
         setup: function (editor) {
                   var self = this;
                    editor.addButton('mybutton', {
                      type: 'listbox',
                      text: 'myList',
                      icon: false,
    
                      onselect: function (e) {    
    
                        editor.insertContent(this.value());
                      },
                      values: newList,
                      onPostRender: function () {
                        // Select the second item by default
                        this.value('&nbsp;<em>Some italic text!</em>');
                      }
                    });
                }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多