2017-07-28 16 views
0

以下示例是向tinyMCE添加自定义下拉列表,是否可以在init tinyMCE后再次更改?例如,在初始化tinyMCE之后,再次用另一个按钮以不同的列表更新列表。 https://codepen.io/tinymce/pen/JYwJVr是否可以在tinymce初始化后更改tinyMCE自定义工具栏列表框值

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>'); 
     } 
    }); 
    } 
}); 

回答

0

我没有发现,我只能自定义下拉更新任何选择。这不是什么好方法,但是我能使它工作的唯一方法。所以我所做的就是删除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>'); 
        } 
       }); 
      } 
});