我的字段值是:
'<td><input type="text" name="data[JobFault][][fault_name]" value='+c[0]+'></td>';
'<td><input type="text" name="data[JobFault][][unit_cost]" value='+c[1]+'></td>';
'<td><input type="text" name="data[JobFault][][unit_price]" value='+c[2]+'></td>';
'<td><button onclick="removeTR('+i+')" class="btn btn-danger">x</button></td>';
[JobFault] => Array
(
[0] => Array
(
[fault_name] => sectionPart
)
[1] => Array
(
[unit_cost] => 22
)
[2] => Array
(
[unit_price] => 21
)
[3] => Array
(
[fault_name] => IC3277
)
[4] => Array
(
[unit_cost] => 22
)
[5] => Array
(
[unit_price] => 22
)
[6] => Array
(
[fault_name] => IC54444
)
[7] => Array
(
[unit_cost] => 33
)
[8] => Array
(
[unit_price] => 33
)
[creator_id] => 2
[centerId] => 1
)
但我想以这种方式............
[JobFault] => Array
(
[0] => Array
(
[fault_name] => sectionPart,
[unit_cost] => 22,
[unit_price] => 21
)
[1] => Array
(
[fault_name] => sectionPart,
[unit_cost] => 22,
[unit_price] => 21
)
[2] => Array
(
[fault_name] => sectionPart,
[unit_cost] => 22,
[unit_price] => 21
)
[creator_id] => 2
[centerId] => 1
)
答案 0 :(得分:0)
这样的事情应该可以解决问题。
'<td><input type="text" name="data[JobFault][0][fault_name]" value='+c[0]+'></td>';
'<td><input type="text" name="data[JobFault][0][unit_cost]" value='+c[1]+'></td>';
'<td><input type="text" name="data[JobFault][0][unit_price]" value='+c[2]+'></td>';
'<td><input type="text" name="data[JobFault][1][fault_name]" value='+c[0]+'></td>';
'<td><input type="text" name="data[JobFault][1][unit_cost]" value='+c[1]+'></td>';
'<td><input type="text" name="data[JobFault][1][unit_price]" value='+c[2]+'></td>';
依此使用1的增量,表单助手就像这样
echo $this->Form->input('JobFault.0.fault_name');
echo $this->Form->input('JobFault.0.unit_cost');
echo $this->Form->input('JobFault.0.unit_price');
echo $this->Form->input('JobFault.1.fault_name');
echo $this->Form->input('JobFault.1.unit_cost');
echo $this->Form->input('JobFault.1.unit_price');
希望这有帮助。