CKEDITOR.replace() undefined



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

此代码返回:UncaughtTypeError:undefined不是函数(对于CKEDITOR行)

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打得很好:

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;
    }
  });
});

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

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

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;
}

或者你可以先得到值,然后使用

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

相关内容

  • 没有找到相关文章

最新更新