+ -
当前位置:首页 → 问答吧 → EXT 复选框Ext.form.checkbox回填数据

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);

作者: maomao5987370   发布时间: 2011-05-14

怎么会不可以呢?
可以这样直接判断啊,比如:
JScript code

if (Ext.getCmp("checkbox14").checked )


你是不是应该用==,而不是=

作者: lfkcn   发布时间: 2011-05-15