• 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();  
    			  	 }
    			   
                }     
                     
                });


  • 相关阅读:
    JS完整获取IE浏览器信息
    C# DataSet和DataTable详解
    linux下mysql导入数据
    Linux上安装mysql
    JDK6+tomcat7+mysql官网下载地址
    Linux常用命令
    mysql 授权
    tomcat7.0学习笔记
    struts2 <s:property/>标签的使用输出时间格式转换
    Linux如何查找软件安装路径?
  • 原文地址:https://www.cnblogs.com/pangblog/p/3395415.html
Copyright © 2020-2023  润新知