简体   繁体   English

在Laravel中迭代抛出复选框列表(即使未选中)

[英]Iterate throw checkbox list, even if not checked, in Laravel

I have a table of items, and if the user selects an item I need to know how many units are assigned to this item. 我有一个项目表,如果用户选择一个项目,我需要知道为该项目分配了多少个单位。 So I created a check box list coming back with the selected items ids and another one for units. 因此,我创建了一个复选框列表,其中包含选定的项目ID和另一个单位的ID。

<td>{{$item->name}}</td>
<td>{{Form::checkbox('itemchks[]', $item->id)}}</td>
<td>{{Form::text('units[]','0')}}</td>

The problem is that, unless the user checks all items we get 2 different-size lists. 问题是,除非用户检查所有项目,否则我们将获得2个不同尺寸的列表。 For ex, when choosing 3 items, and assigning them some units values, the itemchks come back with these ids 例如,当选择3个项目并为其分配一些单位值时,这些项目会返回这些ID

["4","15","23"]

but the units list returns 但单位列表返回

["15","0","18","0","0","0","0","0","20"]

so I can't know, exactly, each id and its correspondent units. 因此我无法确切知道每个ID及其对应的单位。

I'm using laravel 4.2 我正在使用laravel 4.2

Any ideas will be appreciated. 任何想法将不胜感激。

Instead of letting the browser set the key in your units[] array you could do that yourself using the $item->id : 不用让浏览器在您的units[]数组中设置密钥,您可以自己使用$item->id

<td>{{$item->name}}</td>
<td>{{Form::checkbox('itemchks[]', $item->id)}}</td>
<td>{{Form::text('units['.$item->id.']','0')}}</td>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM