如何操作TinyMCE列表框元素?

时间:2016-04-10 12:28:45

标签: javascript tinymce tinymce-4

在TinyMCE中,如何在插件弹出窗口中添加和删除列表框的选项?

1 个答案:

答案 0 :(得分:0)

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