首页 文章

在Tinymce弹出编辑器中插入动态列表框选项

提问于
浏览
1

我正在尝试创建动态列表框值但在控制台中收到此错误:未捕获TypeError:无法分配给只读属性'active'的[

这是我的代码(仅粘贴listbox的代码):

body: [
                {
                    type: 'listbox',
                    name: 'type',
                    label: 'Panel Type',
                    value: type,
                    'values': get_author_list(),
                    tooltip: 'Select the type of panel you want'
                },
        ]
.....

我正在调用此函数来获取动态列表...

function get_author_list() {
    var d = "[{text: 'Default', value: 'default'}]";

    return d;
}

我猜测列表框中的值只采用静态var而不是动态 . 但我需要在此列表中插入动态值 . 请任何人帮我找一个解决方法 . 有没有可能通过ajax插入?

提前致谢!!

1 回答

  • 0

    我需要类似于.NET站点的东西 . 即使不是很好的代码,我希望它可以帮助别人 .

    tinymce.PluginManager.add('DocumentSelector', function (editor, url) {
    // Add a button that opens a window
    editor.addButton('DocumentSelector', {
        text: 'Document',
        icon: false,
        title: "Document Selector",
        onclick: function () {
            var _documentList;
    
            //load all documents
            var _data = JSON.stringify({/* Some data */});
    
            $.ajax({
                type: "POST",
                url: "/api/TinyMCE/GetDocuments",
                data: _data,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                processData: true,
                success: function (data) {
                    _documentList = eval('(' + data + ')');
    
                    // Open window
                    editor.windowManager.open({
                        title: 'Document Selector',
                        body: [
                        {
                            type: 'listbox',
                            name: 'DocURL',
                            label: 'Documents',
                            values: _documentList
                        },
                        {
                            type: 'textbox'
                            , name: 'TextToDisplay'
                            , value: _text
                            , label: 'Text To Display'
                        },
                        {
                            type: 'textbox'
                            , name: 'TitleToDisplay'
                            , value: _title
                            , label: 'Title'
                        },
                        {
                            type: 'listbox',
                            name: 'TheTarget',
                            label: 'Target',
                            values: [{ text: 'None', value: "_self" }, { text: 'New Window', value: "_blank" }],
                            value: _target
                        }
                        ],
                        onsubmit: function (e) {
                            // Insert content when the window form is submitted
    
                        }
    
                    });
    
                },
                error: function (xhr, status, error) {
                    alert("Error! " + xhr.status + "\n" + error);
                }
            });
    
        }
    
    });
    });
    

    这里是一些Behind代码

    public class TinyMCEController : ApiController
    {
    
    public class DocumentsInfo
    {
        // Some data
    }
    
    public class DocumentList
    {
        public string text { get; set; }
        public string value { get; set; }
    }
    
    
    [HttpPost]
    [ActionName("GetDocuments")]
    public object GetDocuments(DocumentsInfo docInfo)
    {
        //Test data
        List<DocumentList> _DocumentList = new List<DocumentList>();
        _DocumentList.Add(new DocumentList  {
            text = "Document1.pdf",
            value = "value1"
        });
    
        _DocumentList.Add(new DocumentList
        {
            text = "Document2.pdf",
            value = "value2"
        });
    
        var jsonSerialiser = new JavaScriptSerializer();
        var json = jsonSerialiser.Serialize(_DocumentList);
        return json;
    
    }
    }
    

相关问题