2013-02-04 76 views
1

作爲學習extjs的一個步驟,我試圖設計有81個塊的Sudoku遊戲。要創建81個塊,我是否需要重複81次以下代碼?或者有什麼辦法在單個父塊內動態創建81個塊?在extjs中動態創建容器

//inside parent container 
{ 
    xtype: 'container', 
    border: 1, 
    height: 30, 
    style: {borderColor:'#565656', borderStyle:'solid', borderWidth:'1px'} 
} 

我試圖使它成爲一個功能和調用它的循環81次,但這個失敗,許多控制檯錯誤鍍鉻沒有結果。我正在使用Sencha extjs 4.1.1a

這裏是我的完整代碼:

Ext.onReady(function(){ 
    Ext.create('Ext.container.Container', { 
    layout: { 
     type: 'column' 
    }, 
    width: 400, 
    renderTo: Ext.getBody(), 
    border: 1, 
    height: 300, 
    style: {borderColor:'#000000', borderStyle:'solid', borderWidth:'1px'}, 
    defaults: { 
     width: 50 
    }, 
    items: [{ 
     xtype: 'container', 
     border: 1, 
     height: 30, 
     style: {borderColor:'#565656', borderStyle:'solid', borderWidth:'1px'} 
    }] 
    }); 
}); 

回答

2

項目僅僅是一個數組,因此動態生成數組:

var i = 0, 
    items = []; 

for (i = 0; i < 5; ++i) { 
    items.push({ 
     html: 'Foo' + i 
    }); 
} 

new Ext.container.Container({ 
    renderTo: document.body, 
    items: items 
}); 
+0

謝謝你..這所做的工作。 :)一個小小的疑問,如何給位置絕對和相對就像在CSS中使用extjs ..? –

+0

我明白了......只是使用'style'屬性:D –

+0

請看這個鏈接http://stackoverflow.com/q/14682976/1577396。 –