欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

基于bootstrap实现多个下拉框同时搜索功能

程序员文章站 2023-02-24 08:10:12
本文实例为大家分享了bootstrap实现下拉框搜索展示的具体代码,供大家参考,具体内容如下 1.第一个下拉框代码

本文实例为大家分享了bootstrap实现下拉框搜索展示的具体代码,供大家参考,具体内容如下

1.第一个下拉框代码

<div class="btn-group col-sm-3 col-xs-6 util-btn-margin-bottom-5 quick-search"> 
       <!--快速查询-->
       <div class="input-group">
        <span class="input-group-addon"><i class="fa fa-search"></i></span>
        <select data-filter-type="2" name="copyfrom" class="form-control select2" data-validate="notempty" style="visibility: hidden;" data-field="name" data-placeholder="搜索数据资源">
         <option value="">请选择数据资源</option>
         <optgroup label="unesco二类中心">
          <#list data.copyfromlist as entity>
          <#if (entity.type?? && entity.type == '1')>
          <option value="${entity.alias!}" <#if (param.copyfrom?? && param.copyfrom == entity.alias)>selected</#if>>${entity.alias!}</option>
          </#if>
          </#list>
         </optgroup>
         <optgroup label="科技动态与进展">
          <#list data.copyfromlist as entity>
          <#if (entity.type?? && entity.type == '7')>
          <option value="${entity.alias!}" <#if (param.copyfrom?? && param.copyfrom == entity.alias)>selected</#if>>${entity.alias!}</option>
          </#if>
          </#list>
         </optgroup>
         <optgroup label="其他">
          <#list data.copyfromlist as entity>
          <#if (entity.type?? && entity.type == '8')>
          <option value="${entity.alias!}" <#if (param.copyfrom?? && param.copyfrom == entity.alias)>selected</#if>>${entity.alias!}</option>
          </#if>
          </#list>
         </optgroup>
        </select>
       </div>
      </div>

2.第二个下拉框代码

<div class="btn-group col-sm-3 col-xs-6 util-btn-margin-bottom-5 quick-search"> 
       <!--快速查询-->
       <div class="input-group">
        <span class="input-group-addon"><i class="fa fa-search"></i></span>
        <select data-filter-type="2" name="cid" class="form-control select2" data-validate="notempty" style="visibility: hidden;" data-field="name" data-placeholder="搜索栏目名称">
         <option value=""></option>
         <#list data.categories as entity>
         <option value="${entity.id}" <#if (param.cid?? && param.cid == entity.id)>selected</#if>>${entity.id} - ${entity.name}</option>
         </#list>
        </select>
       </div>
      </div>

3.后台js代码(url 参数整理)

bindevents:function(){
    var self = this, dom = self.element;
    $('select[name="copyfrom"]', dom).change(function(event){
    self.params.copyfrom = $(this).val();
    var url = self.formatparams(self.params);
    window.location.href = "cekasp_article.htm" + url;
  });

    $('select[name="cid"]', dom).change(function(event){
    self.params.cid = $(this).val();
    var url = self.formatparams(self.params);
    window.location.href = "cekasp_article.htm" + url;
  });

 }

  formatparams:function(params){
    var self = this;
    var url = "";
    for(var param in params){
    if(params[param]){
      url += param + "=" + params[param] + "&";
    }
  }
    if(url.length > 0){
      url = "?" + url.substring(0,url.length-1);
  }
    return url;
  }

 4.后台java部分代码(接收参数,然后过滤器根据参数得到想要的结果)

   string categoryid = request.optstring("cid");
  if (!validateutil.isnull(categoryid)) {
  // 加载栏目信息
    jsonobject jsoncategory = tojsonobject(adminservice.loadbyid(cekaspcategory.class, categoryid));
    response.put("category", jsoncategory);
    param.addfilter("id", filtertype.in, articleidlist, 1);

  }

  string copyfrom = request.optstring("copyfrom");
  if (!validateutil.isnull(copyfrom)) {
    param.addfilter("copyfrom", filtertype.equals, copyfrom);

  }

  list<cekasparticle> articlelist = adminservice.list(cekasparticle.class,param);

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。