尝试禁用 ckeditor 中的按钮时出错

Error when trying to disable a button in ckeditor

我正在尝试在完成某些检查后在页面加载时动态禁用按钮,但编辑器实例未定义。我加载页面的页面:

ckeditor.js
CKEDITOR.replace( 'message', {
    customConfig: 'ckeditor_config'
});
check.js

在文件 check.js 中,我正在尝试动态禁用按钮 :

jQuery(document).ready(function ($) {
    var pollcatid = jQuery('#poll_catid').val();

    if(pollcatid !== undefined)
    {
        CKEDITOR.instances.message.getCommand( 'polls' ).enable();
    }
    else
    {
        CKEDITOR.instances.message.getCommand( 'polls' ).disable();
    }
});

在页面加载时出现以下错误:

Uncaught TypeError: CKEDITOR.instances.message.getCommand(...) is undefined

那么为什么我的文件 check.js 有错误?

我已经想出了办法,通过这样做:

CKEDITOR.on('instanceReady', function(evt){
        // Do your bindings and other actions here for example
        // You can access each editor that this event has fired on from the event
        var editor = evt.editor;

        var pollcatid = jQuery('#poll_catid').val();

        if(pollcatid !== undefined)
        {
            editor.getCommand( 'polls' ).enable();
        }
        else
        {
            editor.getCommand( 'polls' ).disable();
        }
});