weixin_33722405 2017-04-08 14:14 采纳率: 0%
浏览 19

动态下拉Laravel 4

I'm trying to make a dynamic dropdown in Laravel 4 but the subcategory won't show the list

my controller

 public function myform()
{
    $bioskop = Bioskop::where('flag','=',1)->lists('namaBioskop','idBioskop');
    $film=Film::where('flag','=',1)->lists('judulFilm','idFilm');
    return View::make('pengelolaan.tayang.createtayang',compact('bioskop','film'));
}

/**
 * Get Ajax Request and restun Data
 *
 * @return \Illuminate\Http\Response
 */
public function myformAjax($idBioskop)
{
    $studio = Studio::where('idBioskop','=',$idBioskop)->where('flag','=',1)->where('active','=',1)->lists('namaStudio','idStudio');
    return json_encode($studio);
}

route

Route::get('myform',array('as'=>'myform','uses'=>'TayangController@myform'));

Route::get('myform/ajax/{id}',array('as'=>'myform.ajax','uses'=>'TayangController@myformAjax'));

view

   {{Form::open(array('url'=>'myform','method'=>'POST'))}}
            <div class="form-group">
                <div class="col-lg-6">
                    <label for="title">Bioskop </label>
                        <select name="bioskop" class="form-control">
                            @foreach ($bioskop as $key => $value)
                                <option value="{{ $key }}">{{ $value }}</option>
                            @endforeach
                        </select>
                </div>
            </div>
            <div class="form-group">
                <div class="col-lg-6">
                    {{ Form::label('idFilm', 'Film') }}
                    {{ Form::select('idFilm', $film,'',array('class'=>'form-control')) }}
                </div>
            </div>
            <div class="form-group">
                <div class="col-lg-6">
                     <label for="title">Studio</label>
                    <select name="studio" class="form-control"></select>
                </div>
            </div>

javascript

 <script type="text/javascript">
$(document).ready(function() {
    $('select[name="bioskop"]').on('change', function() {
        var idBioskop = $(this).val();
        if(idBioskop) {
            $.ajax({
                url: '/myform/ajax/'+idBioskop,
                type: "GET",
                dataType: "json",
                success:function(data) {

                    $('select[name="studio"]').empty();
                    $.each(data, function(key, value) {
                        $('select[name="studio"]').append('<option value="'+ key +'">'+ value +'</option>');
                    });

                }
            });
        }else{
            $('select[name="studio"]').empty();
        }
    });
});

the parent category is showing but when i pick the parent category the sub category won't show the list based on the parent category, it shows nothing. Can somebody help please? thanks in advance

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥15 stable diffusion
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿