2012-08-28 2 views
4

내 저장소에 채워진 데이터를 사용하여 컨테이너에 구성 요소를 추가하려고합니다. 내 매장 기록을 반복하고 레이블/패널/등을 출력하여 데이터를 표시하려고합니다.EXT.JS가 상점을 순환하고 항목 배열 내부에 구성 요소를 생성합니다.

이것은 내가 지금 통해 반복 해요 방법은 다음과 같습니다

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); 
} 

그러나 물론

, 나는 오전의 ExtJS의 멍청한 놈되고,이 작동하지 않습니다. 이 조언을 구하기 위해 제공 할 수있는 조언과 모범 사례에 대한 조언을 주시면 감사하겠습니다.

내 모델 ItemArray에 항목이 있습니다. ItemArray의 저장소를 반복하고 컨테이너를 만든 다음 ItemArray의 Items를 루프하여 Items로 채 웁니다.

감사합니다.

+0

Ext noob과 아무 관련이 없습니다. 유효한 JS 구문이 아닙니다. –

답변

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 
     }); 
    }); 
});​ 

귀하의 사례는 아직 채워지지 않았습니다. 비동기 적으로로드되기 때문에 약간의 지연이 있습니다.

1
Ext.define('Foo', { 

    initComponent: function(){ 
     // assumes store is loaded with data 
     var store = new Ext.data.Store(), 
      items = []; 

     store.each(function(rec){ 
      items.push({ 
       html: rec.get('aField') 
      }); 
     }); 
     this.items = items; 
     this.callParent(); 
    } 

}); 
관련 문제