通过laravel中的ajax jquery通过复选框获取过滤数据

I am Trying to filter data through checkbox.
while checked on checkbox it shown data list, but while checked second checkbox 1st checbox checked data hide, shown latest one. i dont know why this problem happening. please help me i on trouble.

enter image description here

*HTML/Blade File

@foreach ($popular as $genreTag)
        <li class="lib">

            <a class="open-library" ><input class="genreTag"  id="{{ $genreTag->id}}" type="checkbox" name="">{{{ $genreTag->name }}}</a>
        </li>
    @endforeach
//controller
public function show($id)
    {
        $sortBy = Input::get('sortBy', 'id');
        $dir    = Input::get('direction', 'desc');

        $orderBy = [
                        'tracks'=>[   'order_by'=>$sortBy, 'direction'=>$dir ]
                    ];

        // $tag = $this->tags->findWithOrderBy($id, ['albums', 'composers','elements'],$orderBy);
        $tag = $this->tags->findWithOrderBy($id, ['tracks'],$orderBy);
        /*echo "<pre>";
        print_r($tag->toArray());
        die();*/
        $this->layout->content = View::make('public.tags.tracks', compact('tag'));
    }
//Javascript or Jquery

        $(".genreTag").change(function(){
            var array = [];
            var val = $(this).val();
            var id =  $(this).attr('id');
            if(this.checked){
                array.push(this.val);
                $.get("{{url('tag')}}/" +id, function(data)
                {

                    $('.libraryWrapper').filter(':checked');
                    refreshedPage = $(data);
                    newDemo = refreshedPage.find(".libraryWrapper").html();
                    $('.libraryWrapper').html(newDemo);
                });
            }
            else {

                id.hide();
            }
        // console.log(x.join(','));
});
//route

Route::get('tag/{id}', ['as' => 'tag.tracks', 'uses' => 'TagsController@show']);

我正在尝试通过复选框过滤数据。     选中该复选框时,它显示数据列表,而选中第二个复选框时,第一个复选框则隐藏数据,显示最新的数据。我不知道为什么这个问题发生。请帮助我,我遇到麻烦了。

评论