2013-11-14 4 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; 
     }); 

Я могу получить значение для item1 и item2 с помощью var id = this.getContentElement('tab', 'menu').getValue();var id будет 0 или 1, но я также хочу, чтобы получить item1 и item2, а также.

В своих документах не говорится о том, как его получить. http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.dialog.html

Я не уверен, как это сделать. Может ли кто-нибудь мне помочь? Благодаря!

ответ

0

Вы определили выбранные элементы неправильно (см. docs). Во всяком случае, использовать this.getValue() и сравнить его с this.items в commit методом (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); 
         } 
        } 
       ] 
      }   
     ] 
    }; 
});