new Ext.form.Checkbox({
fieldLabel:'航段显示',
checked:false,
name:'hdxs',
listeners:{check:function(checked,check){
if(check){
searchForm.getForm().findField('hd').setValue(1);
}else{
searchForm.getForm().findField('hd').setValue(0);
}
}
}
}),一个checkbox是这样的.然后想让点击的时候在上面一个function里面有两代不同的代码。控制一些form的显示.想让checkbox点下去的时候就显示出来.没有勾选的时候就不显示.var typeChange = function(){
var form = searchForm.getForm();
switch(form.findField('t_type').getValue()){
case 'DEP_ARR':
if
form.findField('dep').enable();
form.findField('dep').getEl().up('.x-form-item').setDisplayed(true);
form.findField('dep').setValue("");
form.findField('arr').enable();
form.findField('arr').getEl().up('.x-form-item').setDisplayed(true);
form.findField('arr').setValue("");
form.findField('dep2').enable();
form.findField('dep2').getEl().up('.x-form-item').setDisplayed(true);
form.findField('dep2').setValue("");
form.findField('arr2').enable();
form.findField('arr2').getEl().up('.x-form-item').setDisplayed(true);
form.findField('arr2').setValue("");
form.findField('dep3').enable();
form.findField('dep3').getEl().up('.x-form-item').setDisplayed(true);
form.findField('dep3').setValue("");
form.findField('arr3').enable();
form.findField('arr3').getEl().up('.x-form-item').setDisplayed(true);
form.findField('arr3').setValue("");
form.findField('dep4').enable();
form.findField('dep4').getEl().up('.x-form-item').setDisplayed(true);
form.findField('dep4').setValue("");
form.findField('arr4').enable();
form.findField('arr4').getEl().up('.x-form-item').setDisplayed(true);
form.findField('arr4').setValue("");
}else{
form.findField('dep').disable();
form.findField('dep').getEl().up('.x-form-item').setDisplayed(false);
form.findField('arr').disable();
form.findField('arr').getEl().up('.x-form-item').setDisplayed(false);
form.findField('dep2').disable();
form.findField('dep2').getEl().up('.x-form-item').setDisplayed(false);
form.findField('arr2').disable();
form.findField('arr2').getEl().up('.x-form-item').setDisplayed(false);
form.findField('dep3').disable();
form.findField('dep3').getEl().up('.x-form-item').setDisplayed(false);
form.findField('arr3').disable();
form.findField('arr3').getEl().up('.x-form-item').setDisplayed(false);
form.findField('dep4').disable();
form.findField('dep4').getEl().up('.x-form-item').setDisplayed(false);
form.findField('arr4').disable();
form.findField('arr4').getEl().up('.x-form-item').setDisplayed(false);
}
form.findField('agent').disable();
form.findField('agent').getEl().up('.x-form-item').setDisplayed(false);我这样写了.但是在页面中点那个checkbox没有反应.不知道是哪里出了问题.还有那个if里面取值我写的是from.findField('hd).getValue.equals('1').实在是不太懂JS.请大家帮帮忙。
new Ext.form.Checkbox({
fieldLabel:'航段显示',
checked:false,
name:'hdxs',
listeners:{check:function(checked,check){
var field = searchForm.getForm().findField('hd');
if(field)
field[check ? 'hide' : 'show']();
searchForm.doLayout();
}
}
}),
fieldLabel:'航段显示',
checked:false,
name:'hdxs',
listeners:{"check":function(checked,check){
if(check){
searchForm.getForm().findField('hd').setValue(1);
}else{
searchForm.getForm().findField('hd').setValue(0);
}
}
}
}),
new Ext.form.Checkbox({
fieldLabel:'航段显示',
checked:true,
name:'hdxs',
listeners:{check:function(checked,check){
var field = searchForm.getForm().findField('dep');
if(field)
field[check ? 'show' : 'hide']();
searchForm.doLayout();
var field = searchForm.getForm().findField('arr');
if(field)
field[check ? 'show' : 'hide']();
searchForm.doLayout();
}
}
}),然后输入框的确不显示了.但是输入框旁边的fieldLabel还在.这个fieldLabel应该怎么隐藏呢.?
1、组件最好加上id属性 方便操作
2、给组件赋值 Ext.getCmp('组件的id').setValue('值') 通常组件都有这个方法 至少form中的组件都有
3、控制组件显隐 Ext.getCmp('组件的id').hide()或者show()
4、equals这是Java中的比较字符串是否相等的用法 js中没有equals 而是 ==5、from.findField('hd).getValue.equals('1')
如上所标注 getValue是个方法 需改为getValue()
6、我们一般很少用form.findField这样的方法 只有那种复杂的场景需要借助底层代码这样来搞 通常都用Ext.getCmp