EXT 复选框Ext.form.checkbox回填数据
时间:2011-05-14
来源:互联网
最近项目中使用到checkbox组件回填数据问题。
开始按照常理使用Ext.getCmp('id').checked=true;但是该方法不管用。
查看源代码发现
getValue : function(){
if(this.rendered){
return this.el.dom.checked;
}
return this.checked;
}
Ext使用的是dom的属性checked指定的状态随意就这样Ext.getCmp('id').el.dom.checked=true;
这样页面确实是选中状态了,可是发现一个bug。虽然是选中了但是这个时候如果checkbox组件中写的有check事件的话单击2下都不会触动check事件。
终极解决方法:
源文件中介绍
onClick : function(){
if(this.el.dom.checked != this.checked){
this.setValue(this.el.dom.checked);
}
},
setValue : function(v){
var checked = this.checked ;
this.checked = (v === true || v === 'true' || v == '1' || String(v).toLowerCase() == 'on');
if(this.rendered){
this.el.dom.checked = this.checked;
this.el.dom.defaultChecked = this.checked;
}
if(checked != this.checked){
this.fireEvent('check', this, this.checked);
if(this.handler){
this.handler.call(this.scope || this, this, this.checked);
}
}
return this;
}
该方法就是调用Ext.getCmp('id').setValue(true);
开始按照常理使用Ext.getCmp('id').checked=true;但是该方法不管用。
查看源代码发现
getValue : function(){
if(this.rendered){
return this.el.dom.checked;
}
return this.checked;
}
Ext使用的是dom的属性checked指定的状态随意就这样Ext.getCmp('id').el.dom.checked=true;
这样页面确实是选中状态了,可是发现一个bug。虽然是选中了但是这个时候如果checkbox组件中写的有check事件的话单击2下都不会触动check事件。
终极解决方法:
源文件中介绍
onClick : function(){
if(this.el.dom.checked != this.checked){
this.setValue(this.el.dom.checked);
}
},
setValue : function(v){
var checked = this.checked ;
this.checked = (v === true || v === 'true' || v == '1' || String(v).toLowerCase() == 'on');
if(this.rendered){
this.el.dom.checked = this.checked;
this.el.dom.defaultChecked = this.checked;
}
if(checked != this.checked){
this.fireEvent('check', this, this.checked);
if(this.handler){
this.handler.call(this.scope || this, this, this.checked);
}
}
return this;
}
该方法就是调用Ext.getCmp('id').setValue(true);
作者: maomao5987370 发布时间: 2011-05-14
怎么会不可以呢?
可以这样直接判断啊,比如:
JScript code
你是不是应该用==,而不是=
可以这样直接判断啊,比如:
JScript code
if (Ext.getCmp("checkbox14").checked )
你是不是应该用==,而不是=
作者: lfkcn 发布时间: 2011-05-15
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28