2014-09-28 70 views
1

我想提交從菜單按鈕的值,但知道這是不可能的,我必須創建一個隱藏的字段,並在那裏存儲按鈕值。ExtJs提交menubutton值

作爲ExtJs的新手,我似乎無法弄清楚如何做到這一點。以下是我用來檢查按鈕顯示的基本佈局,我可以選擇一種顏色。

getFormItems : function() { 
    var me = this; 

    return [{ 
     xtype : "fieldset", 
     title : "Items to monitor", 
     defaults : { 
      labelSeparator : "" 
     }, 
     items : [{ 
      xtype  : "checkbox", 
      name  : "cpuenable", 
      boxLabel : _("Will monitor CPU Temperature"), 
      fieldLabel : _("CPU Temperature"), 
      checked : false 
     },{ 
      xtype : 'hiddenfield', 
      id : 'buttonvalues' 
     },{ 
      xtype : "button", 
      name : "colours", 
      text : _("Choose Colours"), 
      scope : this, 
      style : { 
       marginTop  : "10px", 
       marginBottom : "10px" 
      }, 
      menu: [{ 
      text: "Main CPU Colour", 
      menu: { 
       xtype : "colormenu", 
       name : "colourc", 
       value : "000000", 
       cls : "menubutton-class", 
       handler: function (obj, rgb) { 
        var colourmField = this.findField('colourc'); 
        colourmField.setValue(rgb.toString()); 
        alert(colourmField.getValue()); 
       } 
      } 
     },{ and so on 

回答

1

好的,這裏是我以前的文章的編輯。我給你舉個例子,如何獲取你想要一個組件內所有的子組件:

例ExtJS的:

{ 
    xtype: 'fieldset', 
    id: 'fsButtons', 
    items: [ 
     { 
      xtype: 'hiddenfield', 
      id: 'hiddenValues' 
     }, 
     { 
      xtype: 'button' 
      color: '000000' 
     }, 
     { 
      xtype: 'button' 
      color: '555555' 
     } 
    ] 
} 

功能,填補了hiddenfield:

function getButtonVars() { 
    var buttonVars = new Array(); 
    //Get all components with xtype 'button' inside the fieldset with id 'fsButtons' 
    Ext.Array.each(Ext.ComponentQuery.query('button', Ext.getCmp('fsButtons'), function(button){ 
     buttonVars.push(button.color); 
    }); 

    Ext.getCmp('hiddenValues').setValue(buttonVars.join(',')); // concats all button values to one string: '000000,555555' etc. 
} 

我希望它現在是明確的: )

http://docs-origin.sencha.com/extjs/4.2.2/#!/api/Ext.ComponentQuery

+0

感謝您的回答,我更新了代碼以chec k如果目前爲止是正確的。 – jhmiller 2014-09-28 12:21:52

+0

每次我嘗試使用Ext.Array時,它都會停止工作的代碼。現在是否有機會檢查代碼是否存在錯誤。 – jhmiller 2014-09-28 12:50:34

+0

我現在完全失去了,嘗試了所有我能想到的使用上述建議,但無法快速完成。 Tyr或其他人可以提供更多關於如何實現目標的細節。 – jhmiller 2014-09-28 18:43:44