---
title: "Ext中ComboBox的模板应用"
author: "ferreousbox"
date: "2009-04-17T13:19:40Z"
tags: []
categories: ["Web前端"]
slug: "ext-combobox"
draft: false
lastmod: "2009-04-17T13:21:21Z"
id: 369492
url: "https://ferreousbox.iteye.com/blog/369492"
---

我们在使用Ext的ComboBox时，默认的主题是将下拉列表的内容居中显示的，这样显得不如传统的select友好，我们可以通过模板（设置ComboBox的tpl属性）来重新显示列表内容，如下：

 

 

```
tpl : '<tpl for="."><div style="text-align:left;" class="x-combo-list-item">{value}</div></tpl>'
```

 

    其中&lt;tpl for="."&gt;是必须的，即遍历每一组数据，相比ext默认生成的列表，我们增加了style="text-align:left;"的部分来使文字居左对齐显示；{value}是占位符，其中value是ComboBox的store中的fields的值，从而就可以达到我们想要的效果了。