How can I manipulate TinyMCE listbox elements?

你。 提交于 2019-12-25 07:07:36

问题


In TinyMCE how can add and remove options to listboxes in a plugin pop up window?


回答1:


editor.addMenuItem('insertValue', {
        text: 'Menu item text',
        context: 'tools',
        onclick: function() {
            availableElements=[
                {
                    text:'Start typing into the search box'
                }
            ];
            var w=editor.windowManager.open({
                title: 'Pop up window title',
                body:[
                    {
                        type:'textbox',
                        name:'title',
                        label:'Search',
                        onkeyup:function(e){
                            $.post('THE URL WHICH GIVE BACK THE OPTIONS AS A JSON').done(function(response){
                                response=JSON.parse(response);
                                for (i in availableElements){
                                    availableElements.pop();
                                }
                                if (typeof response.data!=="undefined"){
                                    for (i in response.data){
                                        availableElements.push({
                                            value:response.data[i].id,
                                            text:response.data[i].title
                                        });
                                    }
                                }
                            });
                        }
                    },
                    {
                        type:'listbox',
                        name:'id',
                        label:'Insert this value',
                        values:availableElements
                    }
                ],
                width:600,
                height:200,
                buttons: [
                    {
                        text:'Insert',
                        onclick:'submit',
                        class:'mce-primary'
                    },
                    {
                        text:'Cancel',
                        onclick:'close'
                    }
                ],
                onsubmit:function(){
                    tinymce.activeEditor.execCommand('mceInsertContent', false, w.find("#id").value());
                }
            });
        }
    });


来源:https://stackoverflow.com/questions/36529726/how-can-i-manipulate-tinymce-listbox-elements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!