cn_godsmell 2010-07-05 17:09
浏览 263
已采纳

关于FormPanel load的时候,checkbox 根据JSON数据自动选中的问题

近日在使用EXTJS 3.1.0开发的时候遇到了FormPanel load 时,Checkbox 无法按照加载的JSON字符串自动选中,

不知道各位有没有遇到类似的问题?附上我的部分代码,请有经验的人帮忙分析一下原因:

这个是FormPanel 中的定义:
[code="java"]
{
xtype: 'checkboxgroup',
fieldLabel: '正确答案',
columns: 4,
items: [
{boxLabel: 'A', name: 'answer_A', inputValue:"A"},
{boxLabel: 'B', name: 'answer_B', inputValue:"B"},
{boxLabel: 'C', name: 'answer_C', inputValue:"C"},
{boxLabel: 'D', name: 'answer_D', inputValue:"D"}
]
}
[/code]

以下是服务端在Form load 的时候返回的 Json 代码:
[code="java"]
{"success":"true",
"data":{"answer_A":"","answer_B":"","answer_C":"","answer_D":"D"}
}
[/code]

请教,为什么选项D无法自动选中?

我参考了 yht19yb 和 microboat 关于 “RadioGroup 和 CheckboxGroup 动态 赋值”的帖子,

但是在我使用了两位 对Ext.form.BasicForm的findField 方法的复写代码之后,执行中FireBug 报错:

f.items.each is not a function

请教是哪里出了问题?

  • 写回答

5条回答 默认 最新

  • works001 2010-07-05 18:14
    关注
        <script type="text/javascript">
    

    Ext.onReady(function(){

    Ext.override(Ext.form.BasicForm,{  
    findField : function(id){          
        var field = this.items.get(id);          
        if(!field){  
            this.items.each(function(f){  
                if(f.isXType('radiogroup')||f.isXType('checkboxgroup')){  
                    f.items.each(function(c){  
                        if(c.isFormField && (c.dataIndex == id || c.id == id || c.getName() == id)){  
                            field = c;  
                            return false;  
                        }  
                    });  
                }  
    
                if(f.isFormField && (f.dataIndex == id || f.id == id || f.getName() == id)){  
                    field = f;  
                    return false;  
                }  
            });  
        }  
        return field || null;  
    }   
    

    });

    Ext.QuickTips.init();
    var data = {"success":"true",  
     "data":{"answer_A":"","answer_B":"","answer_C":"","answer_D":true}  
    } 
    var form = new Ext.form.FormPanel({
        title: 'form',
        frame: true,
        width:400,
        items: [{  
                    xtype: 'checkboxgroup',  
                    fieldLabel: '正确答案',  
                    columns: 4,  
                    items: [  
                    {boxLabel: 'A', name: 'answer_A', inputValue:"A"},   
                    {boxLabel: 'B', name: 'answer_B', inputValue:"B"},  
                    {boxLabel: 'C', name: 'answer_C', inputValue:"C"},  
                    {boxLabel: 'D', name: 'answer_D', inputValue:"D"}  
                    ]  
            }],
            buttons:[{text:"赋值",handler:function(){
                form.form.setValues(data.data);
    
            }}],
        renderTo: 'form'
    });
    

    });





    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘