getValue
setValue
function RadGetValue() { var radios = Ext.getCmp("sltSettlementType"); var v = ""; radios.items.each(function (item) { if (item.getValue()) { v = item.inputValue; } }); return v; } function RadSetValue(v) { var radios = Ext.getCmp("sltSettlementType"); radios.items.each(function (item) { item.setValue(false); if (item.inputValue == v) { item.setValue(true); } }); } Ext.define("Ext.form.CheckboxGroup", { extend: "Ext.form.CheckboxGroup", getValue: function () { var v = []; this.items.each(function (item) { if (item.getValue()) { v.push(item.inputValue); } }); return v; }, setValue: function (vals) { var v = []; v = vals.split(','); this.items.each(function (item) { item.setValue(false); for (var i = 0; i < v.length; i++) { var val = v[i]; if (val == item.inputValue) { item.setValue(true); } } }); } });
RadioGroup不用继承扩展是因为用了之后getValue,setValue的功能实现了,但是基本的点击单选的功能丢失了
CheckboxGroup从数据库中读取
var columns; var items = []; function GetSource() { Ext.Ajax.request({ url: "../Handler/Category.ashx", async: false, success: function (response, option) { var result = Ext.JSON.decode(response.responseText); columns = result.length; for (var i = 0; i < result.length; i++) { var cnName = result[i].CnName; var code = result[i].Code; var clu = { boxLabel: cnName, name: "checksource", inputValue: code }; items.push(clu); } } }); } GetSource(); var checksource = Ext.form.CheckboxGroup({ id: 'checksource', width: 300, xtype: 'checkboxgroup', fieldLabel: '<%=GetLocalResourceObject("AccountCurrencyText") %>', columns: columns, vertical: true, items: items });
var sltSettlementType = new Ext.form.RadioGroup({ fieldLabel: '<% = GetLocalResourceObject("SettlementTypeText") %>', columns: 2, id: "sltSettlementType", labelAlign: 'right', renderTo: Ext.getBody(), width: 300, vertical: true, items: [ { boxLabel: '<% = GetLocalResourceObject("PublicBusinessText") %>', name: 'rd0', inputValue: '0' }, { boxLabel: '<% = GetLocalResourceObject("PrivateBusinessText") %>', name: 'rd0', inputValue: '1' } ] });