我有一个输出类别列表的循环,并创建一个按钮,该按钮会召唤一个Bootstrap模态进行确认。一旦确认,表单就会提交,但那就是出错的地方。表单始终提交列表中的最后一项而不是选定的项。如下所示,我已将值输出到控制台,并且每次都输出正确的值。
例如,目前有9个类别,因此有9个按钮。
控制台输出:
1
音乐
Bootstrap模式显示"删除类别:音乐"
循环:
JavaScriptSerializer js = new JavaScriptSerializer();
string json = js.Serialize(config);
模态:
<table class='table table-striped' id="datatable-table" >
<thead>
<tr>
<th>Name</th>
<th width="100px"></th>
</tr>
</thead>
<tbody>
@foreach($categories as $category)
<tr>
<td><a href="{{ route('categories.show', $category->id) }}">{{ $category->name }}</a></td>
<td>
<button class="btn btn-warning btn-sm btn-danger delete-category-modal" value="{{$category->id}}"
data-toggle="modal"
data-target="#deleteModal"
data-backdrop="static"
data-name ="{{$category->name}}"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button>
</td>
</tr>
@endforeach
</tbody>
</table>
脚本:
<div id="deleteModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Delete Category</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
{{ Form::model($category, ['route' => ['categories.destroy', $category->id], 'method' => 'delete']) }}
{{ Form::submit('Delete', ['class' => 'btn btn-danger', 'name' => 'edit-btn']) }}
</div>
{{ Form::close() }}
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
答案 0 :(得分:0)
我似乎在模态上解决了我自己的问题:
{{Form :: model($ category,['route'=&gt; ['categories.destroy', $ category-&gt; id],'method'=&gt; '删除'])}}
$ category-&gt; id应该是'null'
以便jQuery可以使用所选值
来覆盖它