首页 文章

如何操作TinyMCE列表框元素?

提问于
浏览
0

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

1 回答

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

相关问题