我必须创建一个表格行,我必须动态地生成多个行,并且在该行下面还会有一行也将是多个。
我创建了一个表结构并添加了jquery,但这只适用于第一个主表行。另外,我必须在每个Product_applications_id上添加industry_type_master_id。
我需要这种结果:
[product_industry_applications] => Array
(
[0] => Array
(
[industry_type_master_id] => 1
[Product_applications_id] => 2
)
[1] => Array
(
[industry_type_master_id] => 1
[Product_applications_id] => 3
)
[2] => Array
(
[industry_type_master_id] => 1
[Product_applications_id] => 4
)
)
////代码
<div>
<!--<label>Industry Type</label>-->
<table style='border:thin solid gray;width:100%' class="industrytypeTable">
<tr class="nRow">
<td><?php echo $this->Form->input('product_industry_applications.n.industry_type_master_id', array('div'=>false,'label' => false,'empty'=>'Select Industry Type','style'=>'float:left','options'=>$groups)); ?>
</td>
<td>
<table style='border:thin solid gray;width:100%' class="industrytypeTables">
<tr class="nRows">
<td><?php
echo $this->Form->input('product_industry_applications.ns.industry_type_master_id', array('type'=>"hidden"));
echo $this->Form->input('product_industry_applications.ns.Product_applications_id', array('label' => false,'empty'=>'Select Application','style'=>'float:left','options'=>$subgroups)); ?>
</td>
<td class="actions" style='text-align:left'><a class="removers fa fa-minus fa-fw" ></a>
</td>
</tr>
<tr class="addActionRows">
<td></td>
<td class="actions" style='text-align:left'>
<a class="addRows fa fa-plus fa-fw"></a>
</td>
</tr>
</table>
<?php //echo $this->Form->input('product_industry_applications.n.Product_applications_id', array('label' => false,'empty'=>'Select Application','style'=>'float:left','options'=>$subgroups)); ?>
</td>
<td class="actions" style='text-align:left'><a class="remover fa fa-minus fa-fw" ></a>
</td>
</tr>
<tr class="addActionRow">
<td></td>
<td></td>
<td class="actions" style='text-align:left'>
<a class="addRow fa fa-plus fa-fw"></a>
</td>
</tr>
</table>
<div style="clear:both"></div>
</div>
<script>
$(document).ready(function(){
// industry type
var testSpecificationTable=$('.industrytypeTable');
var addRowHtml=$(testSpecificationTable).find(".nRow")[0].outerHTML;
$(testSpecificationTable).find(".nRow").remove();
var count=0;
var rowEvent=function(elmt){
$(elmt).each(function(){
var _this=this;
$(this).find(".remover").click(function(){
$(_this).remove();
});
$(this).hover(function(){
$(_this).find("td").css("background-color","lightgray");
},function(){
$(_this).find("td").css("background-color","transparent");
});
$(this).find("td").css("border-bottom","thin solid gray");
});
};
$(testSpecificationTable).find(".addActionRow .addRow").click(function(){
var elmt=
$(addRowHtml).insertBefore($(testSpecificationTable).find(".addActionRow"));
$(elmt).find("input,textarea,select").each(function(){
$(this).attr("name",$(this).attr("name").replace("[n]","["+count+"]"));
});
rowEvent(elmt);
count++;
});
$(testSpecificationTable).find(".addActionRow .addRow").click();
//application
var testSpecificationTables=$('.industrytypeTables');
var addRowHtmls=$(testSpecificationTables).find(".nRows")[0].outerHTML;
$(testSpecificationTables).find(".nRows").remove();
var counts=0;
var rowEvents=function(elmt){
$(elmt).each(function(){
var _this=this;
$(this).find(".removers").click(function(){
$(_this).remove();
});
$(this).hover(function(){
$(_this).find("td").css("background-color","lightgray");
},function(){
$(_this).find("td").css("background-color","transparent");
});
$(this).find("td").css("border-bottom","thin solid gray");
});
};
$(testSpecificationTables).find(".addActionRows .addRows").click(function(){
var elmt=
$(addRowHtmls).insertBefore($(testSpecificationTables).
find(".addActionRows"));
$(elmt).find("input,textarea,select").each(function() {
$(this).attr("name",$(this).attr("name").replace("[ns]","["+counts+"]"));
});
rowEvents(elmt);
counts++;
});
$(testSpecificationTables).find(".addActionRows .addRows").click();