Preface
The radiogroup of extjs is placed under the Ext. Form namespace in 3.0, which is also a common control. This article will simplify this component and dynamically specify subitems.
Version
Ext-3.0.0
Body
1. Implementation Code // Ext. Form. radiogroup Extension
Ext. Override (ext. Form. radiogroup ,{
Getitems: function (){
Return this. items;
},
Setitems: function (data ){
This. Items = data;
}
});
Function radiogroup (_ name, flable, _ items, _ columns)
{
/// <Summary>
///
/// OPERATOR: farmer's uncle
// Mailbox: over140@gmail.com
// Bo KE: http://over140.cnblogs.com/
/// Time:
/// Description: Ext. Form. radiogroup Encapsulation
///
/// </Summary>
/// <Param name = "_ name"> name </param>
/// <Param name = "flable"> fieldlabel </param>
/// <Param name = "_ items"> items </param>
/// <Param name = "_ columns"> Columns </param>
/// <Returns> Ext. Form. datefield </returns>
VaR Rg = new Ext. Form. radiogroup ({
Name: _ name,
Fieldlabel: flable
});
If (_ columns! = NULL)
RG. Columns = _ columns;
// Dynamic binding
VaR items = new array ();
If (_ items! = NULL ){
For (VAR I = 0; I <_ items. length; I ++)
{
Items [I] = {};
Items [I]. Name = _ name;
Items [I]. boxlabel = _ items [I] [0];
Items [I]. inputvalue = _ items [I] [1];
If (_ items [I]. length> 2)
Items [I]. Checked = _ items [I] [2];
}
}
RG. setitems (items );
Return RG;
}
Code Description:
A) first, you need to expose the items attribute of radiogroup through extension.
B). Pay attention to the code that dynamically binds the subitem.
2. Use Code VaR pnlzb = new Ext. formpanel ({
Layout: 'form ',
Frame: True,
Buttonalign: 'center ',
Bodystyle: 'padding: 20px ',
Defaults :{
Width: 200,
Allowblank: false,
Blanktext: 'This item cannot be blank! '
},
Labelalign: 'right ',
Labelwidth: 150,
Items :[
New radiogroup ('gender', 'gender', [['male', 'male', true], ['femal', 'female])
],
Buttons :[{
Text: "Submit ",
Handler: function (){
Alert (Ext. encode (pnlzb. Form. getvalues ()));
}
},{
Text: "Remove ",
Handler: function (){
Pnlzb. Form. Reset ();
}
}]
});
Code Description:
A) if you want to obtain the selected value, you can directly obtain the instance. getvalue (). inputvalue of the radiogroup object.
Supplement
1. if a JS error occurs, for example, if setitems is empty, set Ext. override (ext. form. radiogroup... part of the Code is placed in the radiogroup function before setitems. If prototype error is also reported, add adapter \ prototype \ ext-prototype-adapter.js to the project, the directory is the same.
Conclusion
EXT is good, but it can easily produce hundreds of lines of JS Code. Therefore, you can simplify this process when you are free of time, which can save a lot of time for you to repeatedly set attribute errors.
Related Articles of this blog
1. Total extjs grid [ext | gridpanel | gridsummary]