duanhai1455 2017-11-10 08:32
浏览 67
已采纳

如何在编辑模式laravel中的下拉列表中选择默认值

In edit mode my selecte dropdown like this.

<select  name="comic_publisher" id="publishers" >
            @foreach($group as $team)
                <option value="{{$team['group_id']}}">{{$team['comic_group_name']}}</option>
            @endforeach
      </select>

and I want like if I edit the record the selected value associated with that record is by default here should be selected.

I am stuck with the little issue, can anyone please help me how to do that.

Thanks a lot.

  • 写回答

3条回答 默认 最新

  • dongqing904999 2017-11-10 08:46
    关注

    You need to retrieve first database inserted value, and then check that value with all options if match found you can select like,

    $db_selected_value = "2"; // retrieved data
    <select name="comic_publisher" id="publishers" >
            @foreach($group as $team)
                <option value="{{$team['group_id']}}" @if($db_selected_value == $team['group_id']) {{ 'selected' }} @endif>{{$team['comic_group_name']}}</option>
            @endforeach
      </select>
    

    here, @if($db_selected_value == $team['group_id']) {{ 'selected' }} @endif this line matches your old selected value to all the other. and selected selects

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端