请使用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>
答案 0 :(得分:0)
不应该
subcat.append("<option value='"+ index +"'>" + element + "</option>");