我试图将我的ajax调用返回数据和其他代码放在一个函数中。
这适用于自定义fckeditor插件。
我有类似
的东西 function customTag(editor){
var id = editor.config.id;
var instance = this;
//my custom ajax wrapper…….
//the 'dbData' is holding the returned data from ajax.
ajax.onFinished = function(dbData){ console.log(dbData)};
//I want to return this object and use my ajax returned data
return {
title:'Link',
minWidth : 200,
minHeight : 200,
buttons : [CKEDITOR.dialog.okButton, CKEDITOR.dialog.cancelButton],
contents: [
{
id:'tab',
label: 'test here',
elements: [
{
type:'select',
id:'select box',
//I want to use the returned data below
items: [[dbData[0],0],[dbData[1],0] ]
}
]
}
]
}
}
CKEDITOR.dialog.add('customTag', function(editor){
return customTag(editor);
});
我怎样才能解决这个问题。非常感谢!
答案 0 :(得分:1)
在CKEDITOR.dialog.add()
内执行ajax.onFinished
。在那里,创建返回对象并直接将其用于CKEditor。要么是这样,要么使用同步操作。像这样:
ajax.onFinished = function(dbData){
var o = {
title:'Link',
minWidth : 200,
minHeight : 200,
buttons : [CKEDITOR.dialog.okButton, CKEDITOR.dialog.cancelButton],
contents: [
{
id:'tab',
label: 'test here',
elements: [
{
type:'select',
id:'select box',
items: [[dbData[0],0],[dbData[1],0] ] // Use dbData
}
]
}
]
};
CKEDITOR.dialog.add('customTag', function(editor){
return o;
});
};
如果CKE在初始化后调用dialog.add
时遇到问题,请在ajax.onFinished
内初始化它。