在Yii中获取多个复选框值

时间:2017-07-14 01:31:58

标签: javascript php jquery yii

我有一个页面,用户可以在其中选择所需的类别并获取组织列表。至于现在,我已经设法从一个选定的类别中获取数据。

我现在的问题是获取多个选定的类别并从多个ID中检索数据。

enter image description here

类别列表:

   <div class="col-md-4 sidebar well col-md-push-8">
            <div class="sidebar__block">
              <div class="sidebar__inner">
                <h4 class="h4">Filter by category</h4>
                <?php foreach ($categories as $c): ?>
                <div class="form-group">        
                    <div class="checkbox">
                      <input type="checkbox" name="category[]" id="<?php echo $c->id;?>" value="<?php echo $c->id;?>" class="styled" <?php if($c->id==$_GET['category']){ echo 'checked="checked"'; } ?>> 
                      <label for="<?php echo $c->title; ?>"><?php echo $c->title;?></label>
                    </div>
                </div>
                <?php endforeach ?>

                <div class="form-group">
                  <button type="submit" class="btn btn-sd btn-sd-green full-width filter_button" name="subscribe">Filter <i class="icon-right-small"></i></button>
                </div>

              </div>
            </div>
          </div>

数据清单(根据所选类别的组织):

          <div class="col-md-8 col-md-pull-4">
            <!--start show category with title-->
            <div class="lgi__block lgi__block-2" id="appnendGridId">
            <!--start show single category with title-->
              <?php if(!empty($enterprises)): ?>
                <?php foreach ($enterprises as $e): ?>

                  <div class="lgi__item category1">
                    <a class="lgi__item-inner" target="_blank"  href="<?php echo $this->createUrl('frontend/enterprise', array('id' => $e->id)) ?>">

                      <div class="lgi__block-img">
                        <h5 class="lgi__label"><?php if($e->isIdeaEnterpriseActiveAccreditedMembership()): ?><?php echo $e->renderIdeaEnterpriseMembership('text')?><?php endif; ?></h5>
                        <img class="img-responsive-full lgi__img wp-post-image" src="<?php echo $e['imageLogoUrl']; ?>" alt="">
                        <div class="overlay"></div>
                      </div>

                      <div class="lgi__title stripe">
                        <h4><?php echo $e['title']; ?></h4>
                        <p><?php echo ysUtil::truncate($e['text_oneliner'], 85) ?></p>
                      </div>
                    </a>
                  </div>
                <?php endforeach ?>
              <?php else: ?>
                <?php echo Notice::inline('Enterprises not found in this category or keyword') ?>
              <?php endif; ?>

            <!--end show single category with title-->

            </div>
            <!--end show category with title-->

            <div class="row load_more_div">
              <div class="col-sm-12 text-center">
                <button type="button" class="btn btn-sd btn-sd-green full-width load-more-posts collapse please_wait_btn_class">
                <h4 style="margin-top: 7px; color: #fff;">Loading...</h4>
                </button>


                <button type="button" class="btn btn-sd btn-sd-green full-width load-more-posts load_more_btn_class">
                Load More <i class="icon-arr-down"></i>
                </button>
              </div>
            </div>

          </div>

JS:

$(document).on('click','.filter_button',function(e){
  e.preventDefault();
  var category = [];
  $.each($("input[name='category[]']:checked"), function(){            
      window.location.replace('/idea/frontend/explore/category/'+$(this).val());
  });

});

感谢是否有人可以帮助我解决这个问题。

0 个答案:

没有答案