CKEditor:无法获取CKEditor的现有实例

时间:2016-07-07 08:24:42

标签: jquery ember.js ckeditor

我在获取现有实例时遇到了问题。

文字区:

{{ textarea  name=ec.ec_id value=ec.ecl_body placeholder=ec.ecl_en_body   class="form-control" }}

CKEditor的:

function createEditor(name)
{
    CKEDITOR.replace(name, {
        //uiColor: '#379e15',
        resize_dir: 'both',
        resize_maxWidth: '800',
        toolbarGroups: [{name: 'basicstyles', groups: ['basicstyles', 'cleanup']},
            {name: 'paragraph', groups: ['list', 'indent', 'blocks', 'align', 'bidi']},
            {name: 'links'}, {name: 'editing', groups: ['find', 'selection', 'spellchecker']}]

    });
}

createEditor(email.ec_id); //Its working

获取数据:

var data = CKEDITOR.instances[email.ec_id];

错误: 数据未定义

1 个答案:

答案 0 :(得分:0)

已修复,我花了很多时间在这上面并最终修复它。

CKEditor init同时具有名称或ID属性。

例1:

<textarea  id="msg_body" name="msg_body"></textarea>

CKEDITOR.replace('msg_body', {}); //Working

var instance = CKEDITOR.instances['msg_body']; //return instance

例2:

<textarea  id="diffrent_id" name="msg_body"></textarea>

CKEDITOR.replace('msg_body', {}); //Working and ckeditor init successfully

var instance = CKEDITOR.instances['msg_body']; //Not Working return undefined.

例3:

<textarea  id="msg_body" name="diffrent_class"></textarea>

CKEDITOR.replace('msg_body', {}); //Working

var instance = CKEDITOR.instances['msg_body']; //return instance

在emberjs中如果我们不指定id字段,那么ember会自动分配一个余烬ID,因为我无法获得该实例。