---
title: "ext2 的combobox的使用"
author: "beckrabbit"
date: "2007-10-15T21:34:14Z"
tags: []
slug: "ext2-combobox"
draft: false
lastmod: "2007-10-15T21:34:14Z"
id: 132085
url: "https://beckrabbit.iteye.com/blog/132085"
---

用一个combobox来选取用户的登录角色

json数据的格式是这样的 id:xx,name:xx

js 代码

 

01. //===========================combox数据读取=================================
02. var RecordDef = Ext.data.Record.create([
03. {name: 'id'},{name: 'name'}
04. ]);
05. var dataStore=new Ext.data.Store({
06. /设定读取的地址，这里是个action，参数是username也就是用户的id
07. proxy: new Ext.data.HttpProxy({url: '../getUserRole.do?&userid='+username}),
08. /设定读取的格式
09. reader: new Ext.data.JsonReader({
10. id:"id"
11. }, RecordDef),
12. remoteSort: true
13. });
14. dataStore.load();

这样就定义好了数据源

接下来做一个combobox:

js 代码

 

01. var comboxrole= new Ext.form.ComboBox({
02. id:'comboxrole',
03. fieldLabel: '登录角色,
04. store: dataStore,
05. displayField:'name',
06. valueField:'id',
07. typeAhead: true,
08. mode: 'local',
09. triggerAction: 'all',
10. emptyText:'请选择登录角色...',
11. selectOnFocus:true,
12. resizable:true
13. });
14. comboxrole.on('select',comboselect,this);

comboselect是选取数据后触发的事件，想怎么写就怎么写了，代码和图就不贴了