EXT.JS循环遍历商店并在items数组中生成组件

Gal*_*len 5 extjs extjs4

我正在尝试使用我商店中填充的数据向我的容器添加一堆组件.我想遍历我的商店记录并输出标签/面板/等来显示数据.

这就是我现在循环的方式:

  initComponent: function () {
  //Create a container for each array, then in that container, 
  //create a label and wrapping panel, then add the items to the wrapping panel
  this.store = Ext.create('Ext.data.Store', {
     model: 'MyProject.model.ItemArray',
     data: []
  });
  Ext.apply(this, {
     items: [
        this.store.each(function() {
           {
              xtype:'label', text:
              'test'
           }
        })
     ]
  });

  this.callParent(arguments);
}
Run Code Online (Sandbox Code Playgroud)

但当然,作为我的EXTJS菜鸟,这不起作用.我将不胜感激,您可以提供任何建议和最佳实践技巧.

我的模型ItemArray包含Items.我需要遍历我的ItemArrays存储并创建容器,然后循环遍历ItemArray中的Items,用Items填充这些容器.

感谢大家!

Joh*_*est 5

您需要先加载商店,然后在商店回调中生成标签.

var me = this;
me.store.load(function(records) {
    Ext.each(records, function(record) {
        //Add a container for each record
        me.add({
            xtype: 'container',
            items: [] //your labels here
        });
    });
});?
Run Code Online (Sandbox Code Playgroud)

您的商店尚未在您的示例中填充.它也会加载异步,因此会有轻微的延迟.