Subitem of extjs dynamic radiogroup [ext | radiogroup | items]

Source: Internet
Author: User
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]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.