我正在使用主干表单,我想用CKEDITOR替换我的textArea。
这段代码返回:未定义的TypeError:未定义不是函数(用于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;
}
});
});知道为什么第一段代码不起作用吗?
发布于 2014-10-21 17:19:38
您可以将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);
});https://stackoverflow.com/questions/26491031
复制相似问题