2012-07-12 15 views
0

我有一個標準的dojox.mobile.EdgeToEdge列表,裏面有一組dojox.mobile.ListItem s。我需要確保每個列表項目的高度相同。見繪製不佳表現如下:如何在dojox.mobile.EdgeToEdgeList中創建相等高度的ListItems?

標準EdgeToEdgeListListItem S:

+-------------------+ 
| Standard ListItem | 
|-------------------| 
| Standard ListItem | 
|-------------------| 
| Standard ListItem | 
|-------------------| 
| Standard ListItem | 
+-------------------+ 

標準EdgeToEdgeList可變高度列表項;

+-------------------+ 
| Standard ListItem | 
|-------------------| 
| Standard ListItem | 
|-------------------| 
| Standard ListItem | 
| with some long | 
| text and variable | 
| height that wraps | 
| to next line  | 
|-------------------| 
| Standard ListItem | 
+-------------------+ 

EdgeToEdgeList與高度相等列表項(較小的列表項「取」的最大高度):

+-------------------+ 
|     | 
|     | 
| Standard ListItem | 
|     | 
|     | 
|-------------------| 
|     | 
|     | 
| Standard ListItem | 
|     | 
|     | 
|-------------------| 
| Standard ListItem | 
| with some long | 
| text and variable | 
| height that wraps | 
| to next line  | 
|-------------------| 
|     | 
|     | 
| Standard ListItem | 
|     | 
|     | 
+-------------------+ 

我試圖複製通過設置列表項目的variableHeight財產實現第三方案。有沒有一個標準的方法來做到這一點?

編輯:我沒有提到,我以編程方式構建列表,所以我不知道最大的項目的高度。像這樣的工作可以嗎?

var largest = 0; 
array.forEach(list.getChildren(), function(child) { 
    var childHeight = domStyle.get(child.domNode, 'height'); 

    largest = (childHeight > largest) ? childHeight : largest; 
}); 

array.forEach(list.getChildren(), function(child) { 
    domStyle.set(child.domNode, 'height', largest + 'px'); 
}); 

這似乎有點「hack-y」。

回答

0

覆蓋.mblListItem CSS類中的height屬性。

默認情況下,我認爲高度爲43像素。

編輯:我覺得你的代碼將工作,但您需要設置ListItem的是variableHeight讓道場計算多少高度如何讓每個人,然後採取最大,它適用於每個。與您所寫的相似,但添加在variableHeight中,然後在應用最大高度時將其取出。

var largestHeight = 0; 
var list = dijit.byId("list"); 
dojo.forEach(data, function(record) { 
    var listItem = new dojox.mobile.ListItem({ 
     label: data.label 
     variableHeight: true, 
    }); 
    list.addChild(listItem); 
    var currentHeight = (dojo.style(listItem.domNode, 'height'); 
    largestHeight = (currentHeight > largestHeight ? currentHeight : largestHeight); 
}); 

dojo.query('.mblListItem', dojo.byId('list')).forEach(function(node) { 
    dojo.removeClass(node, 'mblVariableHeight'); 
    dojo.style(node, 'height', largestHeight + 'px'); 
}); 
+0

感謝您的答案mccrager。該列表正在編程生成,所以我不知道最大列表項的高度。 – naivedeveloper 2012-07-12 20:00:48