日期:2014-05-16  浏览次数:20481 次

Ext radiogroup 动态加载数据问题
代码如下:
  var formpanel=new Ext.FormPanel({ labelAlign: 'center', renderTo: document.body, layout:'form', frame:true, title: '知识库管理(无线宽带导航页面推送)', bodyStyle:'padding:5px 5px 0', anchor:'95%', items: [ { xtype: 'radiogroup', name: 'biztype', width: 220, columns: 3, fieldLabel: '业务类别', //store:data items:getData() }] }); function getData(){ var conn = new Ext.data.Connection(); conn.request({ // url:'../jfoss/usersearchinfoinitt.action', //数据地址 url:'./combobox.jsp', //数据地址 // url: '', success: function(response) { itemArray = Ext.util.JSON.decode(response.responseText); Ext.getCmp('id').items=itemArray; } }); }
combobox.jsp内容如下:[
{boxLabel: 'type1',name:'type1', inputValue: '01'},
{boxLabel: 'type2',name:'type2', inputValue: '02'}, 
 {boxLabel: 'type3',name:'type3', inputValue: '03'},
 {boxLabel: 'type4', name:'type4',inputValue: '04'}
]
可是firefox调试说:this.items is undefined 肯定是数据获取问题 或者items:getData()这块有问题,
高手帮帮忙啊?急死我了

------解决方案--------------------
给其初始的rdaio,然后返回数据后删掉它,创建新的。
HTML code

<link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css" />
<script type="text/javascript" src="extjs/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="extjs/ext-all.js"></script>
<script>
Ext.onReady(function(){
    var formpanel=new Ext.FormPanel({ 
        labelAlign: 'center', 
        renderTo: document.body,
        layout:'form', 
        frame:true, 
        title: '知识库管理(无线宽带导航页面推送)',       
        bodyStyle:'padding:5px 5px 0', 
        anchor:'95%',
        items:[{
              id:'rd',
              xtype: 'radiogroup',  
              name: 'biztype',    
              width: 220,  
              columns: 3,
              fieldLabel: '业务类别',
              items:[
                {boxLabel: 'type1',name:'type1', inputValue: '01'}, 
                {boxLabel: 'type2',name:'type2', inputValue: '02'}, 
                {boxLabel: 'type3',name:'type3', inputValue: '03'}
              ]
        }]
}); 
  
    function getData(){  
        var conn = new Ext.data.Connection();  
        conn.request({
            url:'./combobox.jsp',
            success: function(response){
                itemArray = Ext.util.JSON.decode(response.responseText);
                var cfg = Ext.getCmp('rd').initialConfig;
                cfg.items = itemArray;
                formpanel.remove(Ext.getCmp('rd'));
                var newrg = new Ext.form.RadioGroup(cfg);
                formpanel.add(newrg);
                formpanel.doLayout();
              }
          });  
    }
    getData() 
});

</script>