2013-03-18 67 views
5

我正在開發一個佔位符插件CKEDITOR,它基本上是完整的。我遇到的問題是我試圖從選擇的對話框中獲取值和說明,並且我只獲取該值。 包含的描述和值的陣列看起來像這樣ckeditor插件對話框選擇從選定的描述

- > items: [['description1', 'value1'], ['description2', 'value2']]< -

返回 - >內容 - >元件與IDdropdown我有setupcommit功能。在這些函數中,我需要獲取描述,就像從選擇選項中獲取名稱一樣。

真的需要這樣一個幫助,在此先感謝

例子 - >

<select> 
    <option value="value1">description1</option> 
    <option value="value2">description2</option> 
</select> 

例如< -

(function() { 

    function placeholderDialog(editor, isEdit) { 

     var lang = editor.lang.phlink, 
      generalLabel = editor.lang.common.generalTab; 

     return { 
      title: lang.title, 
      minWidth: 300, 
      minHeight: 80, 
      contents: [ 
       { 
        id: 'info', 
        label: generalLabel, 
        title: generalLabel, 
        elements: [ 
        { 
         id: 'dropdown' 
         , type: 'select' 
         , label: lang.chooseVal 
         , 'default': 'Detta är default' 
         , items: [['description1', 'value1'], ['description2', 'value2']] 
         , setup: function (data) { 
          // need the description 
          this.setValue(data.title); 
         } 
         , commit: function (data) { 
          // need the description 
          data.title = this.getValue(); 
         } 
        }, 
        { 
         id: 'text', 
         type: 'text', 
         style: 'width: 100%;', 
         label: lang.text, 
         'default': '', 
         required: true, 
         validate: CKEDITOR.dialog.validate.notEmpty(lang.textMissing), 
         setup: function (data) { 
          this.setValue(data.text); 
         }, 
         commit: function (data) { 
          data.text = this.getValue(); 
         } 
        } 
       ] 
       } 
      ], 
      onShow: function() { 
       var data = { tag: 'link', content: "detta är innehåll", title: "Länk till svar", text: "detta är text" }; 
       if (isEdit) { 
        this._element = CKEDITOR.plugins.phlink.getSelectedPlaceHolder(editor); 
        data.title = this._element.getAttribute('title'); 
        data.text = this._element.getText(); 
        data.tag = this._element.getAttribute('data-jztag'); 
       } 

       this.setupContent(data); 
      }, 
      onOk: function() { 
       var data = { tag: 'link', content: null, title: null, text: null }; 

       this.commitContent(data); 

       CKEDITOR.plugins.phlink.createPlaceholder(editor, this._element, data); 

       delete this._element; 
      } 
     }; 
    } 

    CKEDITOR.dialog.add('createplaceholder', function (editor) { 
     return placeholderDialog(editor); 
    }); 
    CKEDITOR.dialog.add('editplaceholder', function (editor) { 
     return placeholderDialog(editor, 1); 
    }); 
})(); 

回答

5

使用以下方法來獲得期權的正文:

var input = this.getInputElement().$; 
console.log(input.options[ input.selectedIndex ].text); 
>> "description1" 
+0

就像我想要的那樣工作,非常感謝你 – Ziinloader 2013-03-19 09:06:51