laravel 5.2: 怎么读取保存在一个列中的checkbox?
比如下面有一组复选框:
{!! Form::open(array('url' => 'foo/bar')) !!}
<div class="checkbox">
<label class="checkbox-inline">
<input type="checkbox" id="checkbox1" name="checkbox[]" value="1"> 1
</label>
<label class="checkbox-inline">
<input type="checkbox" id="checkbox2" name="checkbox[]" value="2"> 2
</label>
<label class="checkbox-inline">
<input type="checkbox" id="checkbox3" name="checkbox[]" value="3"> 3
</label>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
{!! Form::close() !!}在控制器中,接收选中的项:
$checkboxes = $request->input('checkbox');接收后,用json_encode()转换成json格式保存在数据表的一个列中,
问题是:
在“编辑页面”,需要把这些项读出来,显示在“编辑页面”中时,以前选中的项要被选中,没被选中的项不被选中,应该怎么做呢?
laravel 5.2: 怎么读取保存在一个列中的checkbox?
比如下面有一组复选框:
{!! Form::open(array('url' => 'foo/bar')) !!}
<div class="checkbox">
<label class="checkbox-inline">
<input type="checkbox" id="checkbox1" name="checkbox[]" value="1"> 1
</label>
<label class="checkbox-inline">
<input type="checkbox" id="checkbox2" name="checkbox[]" value="2"> 2
</label>
<label class="checkbox-inline">
<input type="checkbox" id="checkbox3" name="checkbox[]" value="3"> 3
</label>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
{!! Form::close() !!}在控制器中,接收选中的项:
$checkboxes = $request->input('checkbox');接收后,用json_encode()转换成json格式保存在数据表的一个列中,
问题是:
在“编辑页面”,需要把这些项读出来,显示在“编辑页面”中时,以前选中的项要被选中,没被选中的项不被选中,应该怎么做呢?
读出来的数据 json_decode()转成数组,在页面循环判断value值 相等的给个checked属性
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号