2014-09-28 59 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