0

我试图将我的 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);
  });

我将如何解决这个问题。非常感谢!

4

1 回答 1

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

于 2013-11-13T07:28:33.367 回答