【发布时间】:2015-12-16 20:29:28
【问题描述】:
我必须创建一个动态输入,所以我使用这个 jquery 插件 : jquery add input area。这只是我在 html 中输入的一部分(对不起,它的代码有点长,因为引导标签):
<?php echo form_open_multipart('', array('id' => 'upload', 'enctype' => "multipart/form-data")); ?>
<div class="box-body no-padding">
<div class="form-group col-sm-3">
<label for="container">Container No</label>
<input type="text" name="container" id="container" class="form-control"/>
</div>
//This is the dynamic input Area, I have two.
<div class="form-group col-sm-6">
<label for="cek_kondisi">Cek Kondisi Top</label>
<table id="list2" class="table table-bordered">
<thead>
<tr>
<th style="width: 70%">Item</th>
<th style="width: 20%">Kondisi</th>
<th style="width: 10%">Act</th>
</tr>
</thead>
<tbody>
<tr class="list2_var">
<td>
<select class="form-control" name="list2_item_0" id="list2_name_0">
<option>Pilih jenis kerusakan... </option>
<?php
foreach ($top_item as $v) {
echo '<option value =' . $v->ID_ITEM_INSPECTION . ' >' . $v->NOMOR_ITEM_INSPECTION . ' - ' . $v->NAMA_ITEM_INSPECTION . '</option>';
}
?>
</select>
</td>
<td>
<select class="form-control" name="list2_kondisi_1" id="list2_name_1">
<option></option>
<?php
foreach ($detail_condition as $v) {
echo '<option value =' . $v->ID_ITEM . ' >' . $v->ALIAS . ' - ' . $v->NAME_ITEM . '</option>';
}
?>
</select>
</td>
<td class="del_area04"><button class="list2_del btn btn-block btn-danger" type="button"><i class="fa fa-trash-o"></i></button></td>
</tr>
</tbody>
</table>
<a href="javascript:void(0)" class="list2_add btn btn-success">Add</a><br>
</div>
<div class="form-group col-sm-6">
<label for="cek_kondisi">Cek Kondisi Bottom</label>
<table id="list3" class="table table-bordered">
<thead>
<tr>
<th style="width: 70%">Item</th>
<th style="width: 20%">Kondisi</th>
<th style="width: 10%">Act</th>
</tr>
</thead>
<tbody>
<tr class="list3_var">
<td>
<select class="form-control" name="list3_item_0" id="list3_name_0">
<option>Pilih jenis kerusakan...</option>
<?php
foreach ($bottom_item as $v) {
echo '<option value =' . $v->ID_ITEM_INSPECTION . ' >' . $v->NOMOR_ITEM_INSPECTION . ' - ' . $v->NAMA_ITEM_INSPECTION . '</option>';
}
?>
</select>
</td>
<td>
<select class="form-control" name="list3_kondisi_1" id="list3_name_1">
<option></option>
<?php
foreach ($detail_condition as $v) {
echo '<option value =' . $v->ID_ITEM . ' >' . $v->ALIAS . ' - ' . $v->NAME_ITEM . '</option>';
}
?>
</select>
</td>
<td class="del_area04"><button class="list3_del btn btn-block btn-danger" type="button"><i class="fa fa-trash-o"></i></button></td>
</tr>
</tbody>
</table>
<a href="javascript:void(0)" class="list3_add btn btn-success">Add</a><br>
</div>
<div class="form-group col-sm-12">
<label>Comments</label>
<textarea class="form-control" rows="7" placeholder="Masukkan comment Anda" name="comments"></textarea>
</div>
</div><!-- /.box-body -->
<div class="box-footer">
<button type="submit" class="btn btn-primary btn-block">Submit</button>
</div>
<?php echo form_close(); ?>
这是jquery
$('#list2').addInputArea({
after_add: function () {
}
});
$('#list3').addInputArea();
使用这样的控制器:
public function add_inspection() {
echo ("<pre>");
print_r($this->input->post());
}
我得到了这样的数组:
Array
(
[condition] => Array
(
[0] => 1
)
[container] => EOLU-123456-7
[cleaning] => Y
[owner] => Eagletainer
[last_cargo] => 9
[vessel] => MV.WAN HAI 171
[insulation] => 2
[tare] => 1200
[gross] => 3000
[capacity] => 3000
[unit_type] => IMO 1
[date_of_manu] => 22071989
[name_manu] => PT.Test
[last25] => 22071989
[cert25] => Test
[last5] => 22071989
[cert5] => Test
[list2_item_0] => 1
[list2_kondisi_0] => 9
[list2_item_1] => 2
[list2_kondisi_1] =>
[list3_item_0] => 12
[list3_kondisi_0] => 9
[list3_item_1] => 13
[list3_kondisi_1] =>
[comments] => Test Comment
)
为了最小化我的数据库服务器的性能,我想使用 insert_batch。基于在docs 上插入批处理的代码,它必须具有数组参数。 那么,我怎样才能将动态输入放入数组中?基于我的 Post Array,这是动态输入:
[list2_item_0] => 1
[list2_kondisi_0] => 9
[list2_item_1] => 2
[list2_kondisi_1] =>
[list3_item_0] => 12
[list3_kondisi_0] => 9
[list3_item_1] => 13
[list3_kondisi_1] =>
我需要:
$data = array(
array(
[list2_item_0] => 1
[list2_kondisi_0] => 9
),
array(
[list2_item_1] => 2
[list2_kondisi_1] =>
)
//SO ON, SO ON
);
我怎样才能做到这一点,我已经两天了,任何帮助都非常感谢。
【问题讨论】:
标签: javascript php jquery codeigniter