下面是:ext中ComboBox的简单用法
//comboBox的数据源,仓库信息 var dsSupplier = new Ext.data.Store({ proxy: new Ext.data.HttpProxy({ url:getRootPath()+'servlet/ProduceTaskServlet?change=sStore' }), reader: new Ext.data.JsonReader({ root: 'gridRows', totalProperty: 'totalCount' }, [ {name: 'STOREID'}, {name: 'NAME'} ]) }); var combo=new fm.ComboBox({ store:dsSupplier, fieldLabel: '仓库', typeAhead: true, triggerAction: 'all', lazyRender: true, listClass: 'x-combo-list-small', valueField:'STOREID', displayField:'NAME' }); var form=new fm.FormPanel({ labelAlign:'right', labelWidth:50, frame:true, defaultType:'comboBox', items:[combo] }); var win =new Ext.Window({ //renderTo: 'window-win', layout:'fit', modal : true, width:500, height:300, closeAction:'hide', items:[form], buttons:[{ text:'生成出库单', listeners:{ click:function(){ alert("ssssss"+Ext.get('STOREID')); } } }] });
后台的数据源 是用servlet表现的。。json格式
response.setContentType("text/xml;charset=UTF-8"); response.setHeader("Cache-Control", "no-cache"); String change=request.getParameter("change"); JSONObject json=new JSONObject(); JSONArray array = new JSONArray(); ProduceTask pt=new ProduceTask(); Resultobj rt=null; PrintWriter out = response.getWriter(); if(change.equals("sStore")){ String cgid=(String)request.getSession().getAttribute("CGID"); try { rt=pt.searchStore(cgid); if(rt.Rows>0){ for(int i=1;i<rt.Rows;i++){ Map<String, Object> map1 = new HashMap<String, Object>(); map1.put("STOREID", rt.getCell("STOREID", i)); map1.put("NAME", rt.getCell("NAME", i)); array.put(map1); } json.put("gridRows", array); json.put("totalCount", array.length()); out.print(json); out.close(); } } catch (GeneralException e) { // TODO Auto-generated catch block e.printStackTrace(); }catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
这个项目中需要导入json的jar包