zoukankan      html  css  js  c++  java
  • 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();  
    			  	 }
    			   
                }     
                     
                });


  • 相关阅读:
    掌握 ActionResult
    EF 的 霸气配置
    MVC 3 数据验证 Model Validation 详解
    Entity Framework 插入数据 解决主键非自增问题
    线程池(C#)
    socket 基础学习
    oracle创建job方法
    C# 任意类型数据转JSON格式
    JDBC(连接数据库的四个主要步骤)
    oracle 存储过程详细介绍(创建,删除存储过程,参数传递等)
  • 原文地址:https://www.cnblogs.com/pangblog/p/3395415.html
Copyright © 2011-2022 走看看