Laravel复选框在实时搜索中始终返回true



我对复选框有问题:执行 LIVEsearch 时,复选框的值始终设置为 1/true。当我在正常搜索(没有 js 文件)中做同样的事情时,我没有这个问题。首先是我的复选框的代码:

{{ Form::checkbox('deleted', '1' , null , array('id' => 'search-deleted'))}}

比我的javascript的代码(我想问题是获取复选框的值)

<script>
$(document).ready(function(){
   $(".search").keyup(function(){
       var staffid=  $("#search-staffid").val();
       var firstName=  $("#search-first-name").val();
       var lastName=  $("#search-last-name").val();
       var birthday=  $("#search-birthday").val();
       var children=  $("#search-children").val();
       var deleted=  $("#search-deleted").val();
       if(staffid == "" && firstName == "" && lastName == "" && birthday == "" && children == "" ) {
               $( "#liveResult" ).html("<b>Suchergebnisse werden hier angezeigt</b>");
       }else {
               $.get( "{{ url('demos/livesearch') }}" +
                    '?staffid=' + staffid +
                    '&first_name=' + firstName +
                    '&last_name=' + lastName +
                    '&birthday=' + birthday +
                    '&children=' + children +
                    '&deleted=' + deleted
                , function( data ) {
                   $( "#liveResult" ).html( data );
            });
       }
   });
});
</script>

如您所见,我还有其他一些领域,它们没有任何问题。最后是我的控制器的代码:

public function liveSearch(Request $request)
{
    $data = [
        'id'            =>  $request->staffid,
        'first_name'    =>  $request->first_name,
        'last_name'     =>  $request->last_name,
        // converts date format only if birthday != null
        'birthday'      =>  ($request->birthday ? date('Y-m-d', strtotime($request->birthday)) : null),
        'children'      =>  $request->children,
        'deleted'       =>  $request->deleted
    ];
    if (is_null($data['id']) && is_null($data['first_name']) && is_null($data['last_name']) && is_null($data['birthday']) && is_null($data['children']))
    {
       return view('staff.livesearch');
    }
    else
    {
        dd ($data['deleted']);
    }
}

复选框的value总是1;你真正想知道的是它是否被选中。

// boolean
var deleted = $("#search-deleted").prop('checked');

相关内容

  • 没有找到相关文章

最新更新