Ext combox 动态 检索

spring mvc + extjs

免费下载

1 ext jar包 点击打开链接

2 ext 中文api 点击打开链接


java code:

 

package com.paic.bbs.action;
 
import java.io.OutputStreamWriter;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import com.paic.bbs.DAO.DBUtils;
import com.paic.bbs.DTO.LoginIsToCollect;
import com.paic.bbs.DTO.SchemaidBean;

public class SchemaidAction  extends AbstractController{

	public ModelAndView handleRequestInternal(HttpServletRequest request,HttpServletResponse response)throws Exception{
		String sql="select * from t_schemaidinfo";
		int total = 0;
		PreparedStatement ps1 = DBUtils.getConnection().prepareStatement(sql);
		 
		ResultSet rs1 = ps1.executeQuery();
		
		List<SchemaidBean> list1 = new ArrayList<SchemaidBean>();
		
		while(rs1.next()){
			SchemaidBean sch =new SchemaidBean();
			sch.setID(rs1.getInt(1));
			sch.setSCHEMAID(rs1.getString(2));
			sch.setDescribe(rs1.getString(3));
			list1.add(sch);
			total++;
		}
		StringBuffer sb=new StringBuffer();
		sb=sb.append("{'root':[");
		for (int i = 0; i < list1.size(); i++) {
			sb.append("{'SCHEMAID':' "+list1.get(i).getSCHEMAID()+"','Describe':'"+list1.get(i).getDescribe()+"'}");
			if(i != (list1.size()-1))
				sb.append(",");

		}
		sb.append("]}");
		
	
		System.out.println(sb.toString());
	    response.setCharacterEncoding("UTF-8");
	    response.getWriter().print(sb.toString());
	    response.getWriter().close();
	        return null;
	    }
}


js code: combox代码

 

 

var combobox = new Ext.form.ComboBox({
                id:'pid',
                fieldLabel: '指标名称',
                store:new Ext.data.Store({  
				proxy: new Ext.data.HttpProxy({  
				url: '/KITWEB/SchemaidAction.do'//请求路径  
				  }),  
					reader: new Ext.data.JsonReader({
					root:'root',
					totalProperty:'total'
				},[
			        {name: 'SCHEMAID'},
			        {name: 'Describe'}
				]),
					autoLoad:true
				 }),  
                displayField: 'Describe',
                valueField: 'SCHEMAID',
                hiddenName:'SCHEMAID',//后台接收这个对像的值
                triggerAction: 'all',
                emptyText: '请选择...',
                allowBlank: false,
                blankText: '请选择SCHEMAID',
                typeAhead : true, 
                minChars:1,
                lazyInit:false,
                mode: 'remote',
              	listeners : {  
                'beforequery':function(e){  
                       
                    var combo = e.combo;    
                    if(!e.forceAll){    
                        var input = e.query;    
                        // 检索的正则  
                        var regExp = new RegExp(".*" + input + ".*");  
                        // 执行检索  
                        combo.store.filterBy(function(record,id){    
                            // 得到每个record的项目名称值  
                            var text = record.get(combo.displayField);    
                            return regExp.test(text);   
                        });  
                        combo.expand();    
                        return false;  
                    }  
                },
                
               'click' : function(){ 
			  		 this.expand();  
			  	 }
			   
            }     
                 
            });


 

 

posted @ 2013-10-29 22:13  pangbangb  阅读(371)  评论(0编辑  收藏  举报