首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CKEDITOR.replace()未定义

CKEDITOR.replace()未定义
EN

Stack Overflow用户
提问于 2014-10-21 15:57:14
回答 1查看 4.5K关注 0票数 0

我正在使用主干表单,我想用CKEDITOR替换我的textArea。

这段代码返回:未定义的TypeError:未定义不是函数(用于CKEDITOR行)

代码语言:javascript
复制
define(['jquery', 'backbone', 'backbone-forms', 'ckeditor'],
  function($, Backbone, CKEDITOR) {

  var Form = Backbone.Form;
  Form.editors.Wysiwyg = Form.editors.TextArea.extend({
    className: 'form-control wysiwyg',

    render: function() {
      Form.editors.Base.prototype.render.call(this);
      this.setValue(this.value);

      CKEDITOR.replace(this.el.getAttribute('name'));
      /* At this point, in the consol I can just get:
      *  CKEDITOR.Editor ,.Field ...
      *  But not .replace, .remove ...
      */

      return this;
    }

  });
});

但是,它对这个verison很好:

代码语言:javascript
复制
define(['jquery', 'backbone', 'backbone-forms'],
  function($, Backbone) {

  var Form = Backbone.Form;
  Form.editors.Wysiwyg = Form.editors.TextArea.extend({
    className: 'form-control wysiwyg',

    render: function() {
      Form.editors.Base.prototype.render.call(this);
      this.setValue(this.value);
         require(['ckeditor'], function(CKEDITOR){
           CKEDITOR.replace("html_content"); //can't get this!
         });

      return this;
    }

  });
});

知道为什么第一段代码不起作用吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-21 17:19:38

您可以将this保存到变量中,并在另一个作用域中使用它。

代码语言:javascript
复制
render: function() {
  var t = this;
  Form.editors.Base.prototype.render.call(t);
  t.setValue(t.value);

  require(['ckeditor'], function(CKEDITOR){
     CKEDITOR.replace(t.el.getAttribute('name'));
  });

  return t;

}

或者您可以先得到值,然后再使用它。

代码语言:javascript
复制
var name = this.el.getAttribute('name');

require(['ckeditor'], function(CKEDITOR){
   CKEDITOR.replace(name);
});
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26491031

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档