2012-08-20 4 views
0

enter image description hereКак вынести панели в Ext Js 4

количество панелей зависит от количества данных из хранилища и должны сделать в форме, показанной выше т.е. две колонн

моего код

Ext.define('ConnectionsFeed.view.Communities',{ 
    extend: 'Ext.container', 
    requires: 'ConnectionsFeed.store.Communities', 
    store: 'Communities', 
    alias: 'widget.communities', 
    layout: 'table', 

initComponent: function(){ 
    var x = this; 
    this.store.each(function(item){ 
    x.add(new Ext.panel.Panel()); 
    }); 
} 
}); 

Ext.create('ConnectionsFeed.view.Communities',{ 
    renderTo: Ext.getBody() 
}); 

но получаю следующее сообщение об ошибке

> Uncaught TypeError: Cannot read property 'isInstance' of undefined 
> ext-all.js:21 (anonymous function) ext-all.js:21 Ext.apply.doProcess 
> ext-all.js:21 (anonymous function) ext-all.js:21 Ext.apply.require 
> ext-all.js:21 (anonymous function) ext-all.js:21 Ext.apply.doProcess 
> ext-all.js:21 Ext.apply.doProcess ext-all.js:21 Ext.apply.process 
> ext-all.js:21 Ext.Class.c ext-all.js:21 Ext.ClassManager.create 
> ext-all.js:21 Ext.apply.define ext-all.js:21 (anonymous function) 

ответ

1

Ext.Store.each() позвольте вам вызвать функцию для каждого элемента в хранилище данных. Эта функция должна добавить экземпляр вашей панели в контейнер с макетом table.

YourStore.each(function(item) { 
    //container declared elsewhere 
    container.add(new YourPanel(item)); 
}); 
+0

Ext.define ('ConnectionsFeed.view.Communities', { удлиняет: 'Ext.container', требует: 'ConnectionsFeed.store.Communities', магазина: 'Сообщество', псевдонима: ' widget.communities', макета: 'стол', InitComponent: функция() { вар х = это; this.store.each (функция (пункт) { x.add (новый Ext.panel.Panel ()); }); } }); Ext.create ('ConnectionsFeed.view.Communities', { renderTo: Ext.getBody() }); я получил следующее сообщение об ошибке выполняющийся это неперехваченным TypeError: Не удается прочитать свойство «isInstance» неопределенной –

+0

Ext.each() должна вызываться после того, как контейнер оказанной, и после загрузки магазина. Добавление его в качестве слушателя к событию 'load' магазина должно работать. – Mchl

1

Вам не хватает вызова this.callParent() в конце initComponent.

1

Также в контейнере нет магазина. Вам нужно создать экземпляр в вашем initComponent и загрузить его.

Ext.define('ConnectionsFeed.view.Communities', { 
    extend: 'Ext.container', 
    requires: 'ConnectionsFeed.store.Communities', 
    store: 'Communities', 
    alias: 'widget.communities', 
    layout: 'table', 

    initComponent: function() { 
     var x = this; 

     x.store = Ext.create('ConnectionsFeed.store.Communities'); 

     //If you override initComponent you need to call its parent 
     x.callParent(); 
    }, 
    afterRender: function() { 
     var x = this; 

     x.store.load({ 
      scope: x, 
      //Callback function after the store has loaded 
      callback: function(records, operation, success) { 
       Ext.each(records, function(record) { 
        //Your logic of add a panel here 
        x.add(Ext.create('....')); 
       }); 
      } 
     }); 

     x.callParent(); 
    } 
}); 

Ext.create('ConnectionsFeed.view.Communities', { 
    renderTo: Ext.getBody() 
});​ 
Смежные вопросы