CKeditor在对话框中动态选择

bcl*_*gan 0 ckeditor

试图弄清楚如何动态填充对话框中的选择菜单...在我迄今为止的所有尝试中,我都无法使其正常工作.

小智 9

我认为你要做的是在插件中动态填充下拉列表.无论出于何种原因,在对话框打开时需要填充下拉列表.

如果是这样,这就是我为类似情况所做的事情:

{
    type: 'select',
    id: 'exam_ID',
    label: 'Select Exam',
    items : [ ['--- Select an Exam---',0] ],
    setup : function(element) {
        var element_id = '#' + this.getInputElement().$.id;
        $.ajax({
            type: 'POST',
            url: 'lib/ckeditor/plugins/customExam/utilities/listExams.aspx',
            data: '{"cpID":' + window.parent.$("#cpID").val() + '}',
            contentType: 'application/json; charset=utf-8',
            dataType: 'json',
            async: false,
            success: function(data) {
                $.each(data.DATA, function(index, item) {
                    $(element_id).get(0).options[$(element_id).get(0).options.length] = new Option(item[1], item[0]);
                });
            },
            error:function (xhr, ajaxOptions, thrownError){
                alert(xhr.status);
                alert(thrownError);
            } 
        });
    }

}
Run Code Online (Sandbox Code Playgroud)

关键是找到CKEditor设置的元素ID,这不是id元素定义中的元素ID .您可以将其id用于其他函数,但如果您计划对元素进行任何更新,则需要获取CKEditor DOM元素.

可能有更好的方法来做到这一点,但这对我有用.