2013-11-14 65 views
0

我想为ckeditor构建一个自定义插件。如何从'select'标签中获取所选项目?

我的问题是,我创建了dialog窗口,它包含'select'菜单。无论用户 选择什么,我都想插入该项目。

这是我的脚本。

function customTag(editor){ 

     return { 
      title:'Audio Link', 
      minWidth : 200, 
      minHeight : 200, 
      buttons : [CKEDITOR.dialog.okButton, CKEDITOR.dialog.cancelButton], 
      onOk: function(){ 
      var id = this.getContentElement('tab', 'menu').getValue(); 
      //not sure what to do to get item1 and item2. 

      }, 
      contents: [ 
       { 
        id:'tab', 
        label: 'test', 
        elements: [ 
         { 
         type:'select', 
         id:'menu', 
         items: [['item1', 0, 'item2' , 1]], 
         } 
        ] 
       } 
      ] 
     } 
    } 

     CKEDITOR.dialog.add('customTag', function(editor){ 

      var ck = new customTag(editor) 
      return ck; 
     }); 

我能够通过使用var id = this.getContentElement('tab', 'menu').getValue();var id01获得价值物品1和ITEM2但我也想item1item2为好。

他们的文档没有多说如何得到它。 http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.dialog.html

我不知道该怎么做。任何人都可以帮助我吗?谢谢!

回答

0

您以错误的方式定义了选择的项目(请参阅docs)。总之,使用this.getValue(),并比较其与this.itemscommit方法(fiddle)找到任何你想要的:

CKEDITOR.dialog.add('myDialog', function(editor) { 
    return { 
     title: 'My Dialog', 
     onOk: function() { 
      this.commitContent(); 
     },   
     contents: [ 
      { 
       id: 'tab1', 
       label: 'First Tab', 
       title: 'First Tab', 
       elements: [ 
        { 
         type:'select', 
         id:'menu', 
         label: 'My select', 
         // This is the correct way of defining items. 
         items: [ 
          [ 'foo', 5 ], 
          [ 'bar', 6 ] 
         ], 
         commit: function() { 
          // Combine value with items to retrieve anything you want. 
          console.log(this.getValue(), this.items); 
         } 
        } 
       ] 
      }   
     ] 
    }; 
}); 
相关问题