我只想在选中单选按钮时调用change事件,但是当我们设置值时,更改事件也会调用...就像这样。
Ext.getCmp('2007').setValue({ '2007': 'NoAccess' });
任何人都可以告诉我如何使用自定义检查事件或任何其他事件,以便我们仅在选中(点击)单选按钮上调用更改事件。
我正在使用Ext.Version 4.2.1。
这是我的代码: -
{
xtype: 'radiogroup',
fieldLabel: ' Admin Notes',
labelStyle: 'font-size: 12px;color:#3399CC;',
margin: '0 0 0 3',
defaultType: 'radio',
id: '2007',
name: '2007',
defaults: {
flex: 1
},
items: [
{
boxLabel: 'Read and Update',
inputValue: 'ReadUpdate',
name: '2007'
}, {
boxLabel: 'Read Only',
margin: '0 0 0 20',
inputValue: 'ReadOnly',
name: '2007'
}, {
boxLabel: 'No Access',
inputValue: 'NoAccess',
name: '2007'
}
],
listeners: {
change: function() {
alert("True");
},
答案 0 :(得分:2)
Before to use setValue()
first you need to use following two methods of RadioGroup
.
1). suspendEvent
or suspendEvents
to Suspends the firing of particular or all events
.
2). radiogroup.setValue({name:'value'})
the radio with corresponding name and value will be set.
3). resumeEvent
or resumeEvents
to resumes firing of the named event or all events.
In this FIDDLE, I have created a demo using radiogroup
. I hope it will help you to achieve your requirement.
Code Snippet
Ext.create('Ext.form.Panel', {
title: 'RadioGroup example with change event call when dyanmic value set.',
bodyPadding: 10,
renderTo: Ext.getBody(),
items: [{
xtype: 'radiogroup',
fieldLabel: 'Admin Notes',
defaultType: 'radio',
id: '2007',
defaults: {
name: '2007'
},
items: [{
boxLabel: 'Read and Update',
inputValue: 'ReadUpdate'
}, {
boxLabel: 'Read Only',
margin: '0 0 0 20',
inputValue: 'ReadOnly'
}, {
boxLabel: 'No Access',
inputValue: 'NoAccess'
}],
listeners: {
change: function (cmp, newValue) {
Ext.Msg.alert('Success', 'Checked value is :- ' + newValue['2007']);
}
}
}],
listeners: {
afterrender: function () {
var rb = Ext.getCmp('2007');
rb.suspendEvents();
rb.setValue({
'2007': 'NoAccess'
});
rb.resumeEvents();
}
}
});