0

我有一个组合框,用户在其中选择一个值,该值被传递到复选框数据存储,并从数据库(oracle)动态填充。我尝试了下面的代码。似乎选定的参数正在传递给复选框,我可以看到控制台上正在填充数据。我只是无法在表单上呈现复选框。我得到的错误是: typeError: this.items[0] is undefined。

    testArray = new Array();
    var testStore = new Ext.data.JsonStore({
        proxy:new Ext.data.HttpProxy({
        method:'GET',
        prettyUrls:false,
        url:'kiu.htm',
        listeners:{
            'loadexception':{
            fn:test.form.data.loadException
            }
        }
        }),
        fields:["id", "display"],
        reader:new Ext.data.JsonReader({
        id:'id',
        root:'results',
        totalProperty:'totalCount',
        fields:new Ext.data.Record.create([
            {name:'id',type:'int'},
            {name:'display',type:'string'}
        ])
        }),
        listeners:{      
        load: function(t, records, options, success) {
            for(var i=0; i<records.length; i++) {
              testArray.push({name:records[i].data.id, boxLabel: records[i].data.display});
              alert(testArray[i].id);
            }
        }
        }
    });


    {
                         xtype:'combo',
                         id:'comboid3',                         
                         store:combostore,
                         displayField:'display',
                         valueField:'id',
                         tabIndex:1,
                         loadingText:'Loading combo...',
                         listeners :{
                                   select:function(event){
                                         testStore.baseParams = {
                                                "comboid":Ext.getCmp('comboid3').getValue()
                                            };                                        

                                         testStore.load();

                                    }
                         }

                   },
                   {


                                xtype:'checkboxgroup',
                                                         fieldLabel:'Check',                             
                               items:testArray
           }

帮助将不胜感激!

4

1 回答 1

0

指定 Ext JS 版本总是有帮助的。看来这必须是 2.x 或 3.x 而不是当前版本。

问题在于时间,加载调用是异步的,因此通过尝试以这种方式使用 testArray,您可能会在它解析复选框组的 items 属性时引用一个空数组。您有几个选择...一个是获取对复选框组的引用并将项目添加到其中,另一个是在调用返回之前根本不将复选框组放入表单中,然后添加它填充的项目数组。无论哪种情况,您都可能需要从加载处理程序函数中查找对 FormPanel 或 CheckboxGroup 的组件引用,并调用“add”方法来添加子项。

于 2013-02-26T06:13:37.977 回答