Javascript TinyMCE 4更改编辑器上的工具栏按钮文本单击

Javascript TinyMCE 4更改编辑器上的工具栏按钮文本单击,javascript,tinymce,tinymce-4,tinymce-4.2,Javascript,Tinymce,Tinymce 4,Tinymce 4.2,使用tinyMCE 4.2,每次用户单击编辑器中的任意位置时,我都需要更改(自定义)工具栏按钮的文本 以下是相关代码: tinymce.init({ //code ommitted... toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link

使用tinyMCE 4.2,每次用户单击编辑器中的任意位置时,我都需要更改(自定义)工具栏按钮的文本

以下是相关代码:

tinymce.init({

    //code ommitted...

    toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image jbimages navigationbutton glossary",

    setup: function(editor){

        //add "Glossary" button
        editor.addButton('glossary', {
            name: 'glossary',
            text: 'Glossary',
            onclick: function(){
                /*
                //commented on purpose
                var button = this;
                var updatedButtonText = "Some updated button text";
                button.text = updatedButtonText;
                */
            }
        });//end addButton

        editor.on('click', function(){
            var updatedButtonText = "Some updated button text";

            //update the button text:
            editor.buttons.glossary.text = updatedButtonText; //doesn't work
            window.parent.tinyMCE.activeEditor.buttons.glossary.text = updatedButtonText; //doesn't work either

            //confirm changes:
            console.log(editor.buttons.glossary.text); //correctly prints "Some updated button text"
            console.log(window.parent.tinyMCE.activeEditor.buttons.glossary.text); //correctly prints "Some updated button text" as well
        });

    }//end setup
});//end tinymce.init
所以问题是,虽然按钮对象的
text
属性确实发生了变化,但这种变化并没有反映在编辑器中,而按钮文本仍然是“词汇表”。 有趣的是,如果我通过按钮的
onclick
函数执行完全相同的操作(因此,如果我取消注释注释的代码块),那么它将完全按照预期工作-按钮文本将在编辑器中更新


我花了几个小时在TinyMCE 4的文档中试图找到一些相关信息,但显然是徒劳的。有什么想法吗?

一旦加载了编辑器的工具栏,TinyMCE不支持更改按钮的图标/文本。如果将按钮切换为“开”或“关”(例如,将光标放在粗体或非粗体文本上时粗体按钮的作用),则可以进行更改,但不能更改实际文本/图标


编辑器完全加载后,用于定义术语表按钮的JavaScript对象仍在内存中,因此您可以对该对象执行更改属性值或console.log该值之类的操作,但TinyMCE不会返回并查看该按钮对象,并在加载工具栏后更新按钮

哇,我没想到。因此,如果在按钮的
onclick
函数中更改了
text
属性,它确实会更新按钮,但如果在编辑器的
onclick
函数中更改了
text
属性,它不会更新按钮?因为如果是这样的话,为什么会这样设计对我来说没有多大意义……即使我将代码放入按钮自己的onClick事件中,我也无法在UI中更改按钮的文本。(它将在JavaScript对象中更改,但不会在工具栏上显示)您可以制作一个JS小提琴来显示它的工作情况吗?