2013-02-04 29 views
2

我對extjs非常陌生。我想用extjs來設計數獨遊戲。直到現在我也做了以下內容:使用extjs設計數獨

Ext.onReady(function(){ 

var i = 0, 
items = [], 
childItems = []; 

for (i = 0; i < 9; ++i) { 
    childItems.push({ 
      xtype: 'container', 
      height: 50, 

      style: {borderColor:'#000000', borderStyle:'solid', borderWidth:'1px',width: '40px'} 
     }); 
} 
for (i = 0; i < 9; ++i) { 
items.push({ 
     xtype: 'container', 
     height: 150, 
     layout: { 
     type: 'column' 
     }, 
     style: {borderColor:'#000000', borderStyle:'solid', borderWidth:'1px',width: '143px'}, 
     items: childItems 
    }); 
} 
Ext.create('Ext.container.Container', { 
    layout: { 
     type: 'column' 
    }, 
    width: 450, 
    renderTo: Ext.getBody(), 
    border: 1, 
    height: 450, 
    style: {borderColor:'#000000', borderStyle:'solid', borderWidth:'1px',marginLeft: 'auto',marginRight: 'auto', marginTop: '30px'}, 

    items: items 
}); 
}); 

我的問題是,由於邊界的,這些塊有一定的空間,甚至這類似於用簡單的HTML(div的設計,可能是因爲使用CSS )。請幫忙..

設計看起來不一樣jsfiddle

編輯:我想盡可能避免使用CSS(javascript樣式也)。

+0

你爲什麼不張貼的jsfiddle? –

+0

「設計在jsfiddle中看起來不同」(我不知道爲什麼)。無論如何,這裏是鏈接http://jsfiddle.net/X6kQK/ –

回答

5

請閱讀API適用於border。沒有定義任何樣式,不可能使用簡單的容器。

對於在默認情況下沒有邊框組件,設置這不會使 邊框單獨出現。您還需要指定邊框顏色和款式

但是,你應該使用表格佈局,我想對你使事情更加容易。

下面是使用您例如表佈局(快速和骯髒的變異,但它應該顯示的伎倆)

JSFiddle

for (i = 0; i < 9; ++i) { 
    childItems.push({ 
     xtype: 'container', 
     width: 50, 
     height: 50, 
     html: i + '', 
     style: {borderColor:'#000000', borderStyle:'solid', borderWidth:'1px'} 
    }); 
} 
for (i = 0; i < 9; ++i) { 
    items.push({ 
     xtype: 'container', 
     layout: { 
      type: 'table', 
      columns: 3 
     }, 
     style: {borderColor:'#000000', borderStyle:'solid', borderWidth:'1px'}, 
     items: childItems 
    }); 
} 
Ext.create('Ext.container.Container', { 
    layout: { 
     type: 'table', 
     // The total column count must be specified here 
     columns: 3 
    }, 
    renderTo: Ext.getBody(),  
    style: {borderColor:'#000000', borderStyle:'solid', borderWidth:'1px', margin: '30px'}, 
    items: items 
}); 
+0

謝謝你的幫助..我可以使用'panel'而不是'container'嗎?我正在嘗試在這裏創建一個類似於'div'的元素。否則我應該用'容器'本身。 –

+0

@Mr_Green當然可以。但是你應該決定是否需要一個小組,並且這一切都取決於你計劃的大小以及每個領域應該如何表現。我建議你採用精益的方式,即使用精益課程和精益佈局。而使用這個小小的css行並沒有什麼不好,所以不應該在這裏打擾你。如果所有的數據都依賴於數據,你也可以使用一個模板來直接渲染html並附加dom監聽器(這將是最好的解決方案,但是工作量最大),最終你會得到一個單獨的類,它會忽略一些要呈現的數據) – sra

+0

謝謝你解釋...我有一個小小的懷疑。在我的項目(數獨)中,我試圖在用戶按下特定面板時更改所有面板的顏色。怎麼做?我也嘗試'聽衆:{ \t \t \t \t \t '渲染':函數(面板){ \t \t \t \t \t panel.body.on( '點擊',函數(){ \t \t \t \t \t \t面板。身體。setStyle('background','red') \t \t \t \t \t}); \t \t \t \t} \t \t \t}'但是沒有用.. –