使用Database ....和Jquery的Laravel 5.1 Dependent下拉列表

时间:2015-11-20 09:43:54

标签: jquery laravel

请使用laravel 5.1来帮助操纵依赖下拉列表.... 这是我的主要类别

<div class="form-group col-md-10">
       {!! Form::label('Main Cateogry') !!}
       {!! Form::select('category', (['0' => 'Select Category'] + $category), null, ['class' => 'form-control required', 'id'=>'cat', 'data-url'=>'/admin/dropdown']) !!}

</div>
<div class="form-group col-md-10">
       {!! Form::label('Sub Category Name') !!}
       {!! Form::select('subcategory', (['0'=>'Select Sub Category'] + $sub_cat), null, ['class'=>'form-control','id'=>'subcat']) !!}
</div>

此子类别(loadcat.blade.php)**

@foreach($sub_cat as $sub)
<option value="{{ $sub->id}}">{{$sub->sub_cat_name}}</option>
@endforeach

<script>
          $(document).ready(function($){
             $('#cat').change(function(){
              $.get($(this).data('url'),
               { option: $(this).val() },
                 function(data) {
                   var subcat = $('#subcat');
                   subcat.empty();
                   $.each(data, function(index, element) {
                   subcat.append("<option value='"+ element.id +"'>" + element.name + "</option>");
                });
              });
            });
         });
 </script>

1 个答案:

答案 0 :(得分:0)

不应该

subcat.append("<option value='"+ index +"'>" + element + "</option>");