iteye_1921 2011-12-13 11:46
浏览 342
已采纳

动态生成checkboxgroup出现的两个问题,麻烦给看一下

下面是我做动态生成checkbox的一个demo.不过有两个问题一直无法解决,麻烦各位帮忙看下:
1, 如果checkbox在初始化的时候就checked(选中),取消选中的时候事件没有触发.比如例子上checkbox B刚开始是代码给选中的,取消B的选中,上面的文本框不会出现单个C,如果单选中一个C,文本框应该显示C.
2, 点击动态生成,总是提示this.ownerCt.forcelayout is null or undefined.好像是render不对,不知道原因在哪.可是通过调试cbGroup.ownerCt.forceLayout是false.
请各位帮忙看看,谢谢了!下面是代码




Hello World Window Example



<br> Ext.onReady(function(){<br> var win;<br> var cb_Group;<br> var data = &#39;&#39;;<br> function funCheck(thisCheck){<br><br> var selectStr = &quot;&quot;;<br> for (var j=0;j&lt;5 ;j++ )<br> {<br><br> var cbObj = Ext.getDom(&quot;name&quot;+j);<br> if (cbObj &amp;&amp; cbObj.checked)<br> {<br> selectStr = selectStr + Ext.getDom(&quot;name&quot;+j).value ; <br> }<br> }</p> <pre><code> Ext.getDom(&quot;selectValue&quot;).value = selectStr; }; function setChecked(){ var selectValue = Ext.getDom(&quot;selectValue&quot;).value; selectValue = &#39;BC&#39;; for (var j=0;j&lt;3 ;j++ ) { var labelText = Ext.getDom(&quot;name&quot;+j).value; if (selectValue.indexOf(labelText) &gt;= 0) { Ext.getDom(&quot;name&quot;+j).checked = true; }else{ Ext.getDom(&quot;name&quot;+j).checked = false; } } }; function dynamicGen(){ var cbGroup = Ext.getCmp(&#39;cbCon&#39;); cbGroup.removeAll(); var new_cbg = new Ext.form.CheckboxGroup( { xtype: &#39;checkboxgroup&#39;, fieldLabel: &#39;新的多选组&#39;, id:&#39;ElementTypeID&#39;, name :&#39;ElementTypeID&#39;, columns: 10 }); var newItems=[]; for(var i=0;i&lt;5;i++) { var lText = String.fromCharCode(65 + i); var chkNew = {boxLabel: lText, name: &quot;name&quot;+i, inputValue: lText , isChecked : false ,listeners: { check : funCheck}}; newItems.push(chkNew); } new_cbg.items = newItems; cbGroup.items.add(new_cbg); alert(cbGroup.ownerCt.forceLayout); cbGroup.doLayout(false, false); }; var items=[]; for(var i=0;i&lt;3;i++) { var labelText = String.fromCharCode(65 + i); var chk = {boxLabel: labelText, name: &quot;name&quot;+i, inputValue: labelText , isChecked : false ,listeners: { check : funCheck}}; items.push(chk); } var cb_Group = new Ext.form.CheckboxGroup( { xtype: &#39;checkboxgroup&#39;, fieldLabel: &#39;元素类型&#39;, id:&#39;ElementTypeID&#39;, name :&#39;ElementTypeID&#39;, columns: 10, anchor:&quot;95%&quot;, msgTarget:&quot;side&quot; }); cb_Group.items = items; if(!win){ win = new Ext.Window({ title : &#39;多ceckbox动态生成测试窗口&#39;, xtype:&quot;window&quot;, width : 900, height : 600, plain : true , items : [{ xtype:&quot;fieldset&quot;, layout:&quot;form&quot;, items:[ { xtype:&quot;textfield&quot;, id : &#39;selectValue&#39;, fieldLabel:&quot;选项值&quot;, anchor:&quot;100%&quot; } ] },{ xtype:&quot;fieldset&quot;, layout:&quot;form&quot;, id : &#39;cbCon&#39;, renderTo : this.panel, items:[ cb_Group ] }, { baseCls:&quot;x-plain&quot;, buttons : [{ type:&quot;button&quot;, text:&quot;动态生成&quot;, handler : function() { dynamicGen(); } }] } ] }); } win.show(); setChecked(); }); &lt;/script&gt; </code></pre> <p></head><br> <body></p>
  • 写回答

1条回答 默认 最新

  • works001 2011-12-13 19:18
    关注

    [quote]new_cbg.items = newItems;
    cbGroup.items.add(new_cbg);
    [/quote]
    改成如下:
    [code="java"]new_cbg.items = newItems;
    cbGroup.add(new_cbg); [/code]

    我用3.1版本测试的 成功 不报错 我点击取消选中的时候 事件触发了 上面的textfield内的值也发生变化了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 怎么在stm32门禁成品上增加记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 解riccati方程组