ExtJs combobox设置为带搜索功能的控件

前端代碼:

{
                  xtype:'combo',
                  triggerAction:  'all',
                  emptyText:'輸入模號',
                  selectOnFocus:true,
                  editable:true,
                  typeAhead: true,
                  fieldLabel:     '模號',
                  name:           'mold_id',
                  hiddenName:     'mold_id',
                  displayField:   'value',
                  valueField:     'value',
                  allowBlank: false,
                  maxHeight: 600,
                  listWidth: 100,
                  anchor:'95%',
                  lastQuery: '',
                  store: new Ext.data.ArrayStore({
                        url : 'mold_new_followAction.do?actionType=get_mold_list',
                        fields : ['value'],   //後臺返回數組,前端接收值
                        listeners: {
                            exception : function(misc){
                                    form.getForm().findField('mold_id').setValue('');
                            }
                        },
                        autoLoad : true
                    })
            },{
                xtype:'combo',
                fieldLabel:'對比模號',
                id:'compare_mold_id',
                allowBlank:false,
                typeAhead: true,
                triggerAction:'all',
                displayField:'value',
                valueField:'value',
                anchor:'95%',
                value:'',
                lastQuery: '',
                store: new Ext.data.ArrayStore({
                        url : 'mold_new_followAction.do?actionType=get_mold_list',
                        fields : ['value'],
                        listeners: {
                            exception : function(misc){
                                    Ext.getCmp('compare_mold_id').setValue('');
                            }
                        },
                        autoLoad : true
                    })
            }

後臺代碼:

    public ActionForward get_mold_list(ActionMapping actionMapping,
                                          ActionForm actionForm,
                                          HttpServletRequest httpServletRequest,
                                          HttpServletResponse httpServletResponse) throws
        IOException, ServletException, SQLException {
      String mold_id = httpServletRequest.getParameter("query");  //這個是combobox自帶的參數(取控件中輸入的值)
      Connection conn = null;
      Statement stmt = null;
      ResultSet rs = null;
      DataSource datasource = null;
      ServletContext context = null;
      context = servlet.getServletContext();
      datasource = (DataSource) context.getAttribute(Globals.DATA_SOURCE_KEY);
      String json = "";
      String tempsql = "";
      try {
        conn = datasource.getConnection();
        stmt = conn.createStatement();
        tempsql = "select mold_id from mold with (nolock) where mold_id like '%"+mold_id+"%' "+
                  " union select mold_id from tsql.gdberp.dbo.mold with (nolock) where mold_id like '%"+mold_id+"%'";
        //System.out.println(tempsql);
        rs = stmt.executeQuery(tempsql);
        while (rs.next()) {
                json += "['" + rs.getString("mold_id")+ "'],";
        }

        if (json.length() > 0) {
                json = json.replace("null", "");
                json = json.substring(0, json.length() - 1);
                json = "[" + json + "]";
        } else {
                json = "{\"success\":\"false\",\"message\":\"no result\"}";
        }
        //System.out.println(json);
      }
      catch (SQLException e) {
        System.err.println(e.getMessage());
      }
      finally {
        if (rs != null) {
          rs.close();
          rs = null;
        }
        if (stmt != null) {
          stmt.close();
          stmt = null;
        }
        if (conn != null) {
          conn.close();
          conn = null;
        }
      }

      try {
        httpServletResponse.setContentType("text/json; charset=utf-8");
        httpServletResponse.getWriter().write(json);
      }
      catch (IOException ex) {
        ex.printStackTrace();
      }
      return actionMapping.findForward("");
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值