2011-03-31 56 views
0

我正在构建一个复选框组,其中的商品来自在Ext.OnReady函数中加载的商店。我试图将这个复选框组添加到一个formpanel中,并在add()调用中得到这个错误。 'events'为空或不是对象。动态添加复选框组到一个窗体面板

这里是我与尝试代码..

Ext.onReady(function() { 
{ 
    store.each(function (record) { 
     var itemID = record.get('itemID') 
     var itemDesc = record.get('itemDesc'); 
     jsonDataArray.push([itemID,itemDesc]); 
    }); 

    myCheckboxGroup = new Ext.form.CheckboxGroup({ 
     id: 'chk1', 
     xtype: 'checkboxgroup', 
     width: 520, 
     border: true, 
     items: jsonDataArray 
    }); 

    myForm.add(myCheckboxGroup); 
    myForm.doLayout(); 
} 

var myForm = new Ext.form.FormPanel({ 
    id: 'myForm', 
      region: 'center', 
      border: true, 
      autoHeight: true, 
      items: myCheckboxGroup 

}); 
+0

演示你能解决你的代码的格式吗?很难说出发生了什么,它看起来像JavaScript是无效的。 – Craig 2011-03-31 13:39:53

回答

1

使用的xtype有由布局管理器创造了一切,确保你是给你一些群体复选框来呈现,并定义一个布局类型为你的形式。你也需要把这个表单放在别的东西里面(比如一个窗口)或者把它呈现给页面主体。

var myForm = new Ext.form.FormPanel(
{ 
    id:  'myForm', 
    region: 'center', 
    layout: 'form', 
    border: true, 
    autoHeight: true, 
    items: [{ 
     id: 'chk1', 
     xtype: 'checkboxgroup', 
     width: 520, 
     border: true, 
     items: [ 
      {boxLabel: 'Item 1', name: 'cb-1'}, 
      {boxLabel: 'Item 2', name: 'cb-2', checked: true}, // checked 
      {boxLabel: 'Item 3', name: 'cb-3'}, 
     ] 
    }] 
}); 

现在只需用您的JSON版本替换'items'代码就可以了。确保你已经从你的Ajax调用中返回并在你尝试这个之前将你的响应转换成JSON。

查看此主题的论坛主题以获取更多信息:ExtJs Forum Thread

0
new Ext.form.FormPanel({ 
    title: 'Test Form', 
    labelWidth: 120, 
    width: 350, 
    padding: 10, 
    tbar: [{ 
     text: 'Add CheckboxGroup', 
     handler: function() { 
      formPanel.add({ 
       xtype: 'checkboxgroup', 
       fieldLabel: 'My CheckboxGroup', 
       columns: 1, 
       items: items 
      }); 
      formPanel.doLayout(); 
      this.disable(); 
     } 
    }], 
    items: comboBox, 
    renderTo: 'output' 
}); 

这里http://ext4all.com/post/extjs-3-add-a-checkboxgroup-dynamically-to-a-form