在play 2框架中,我正在使用一个函数来创建表行(如下所示)。我如何使用Jquery在表中添加具有新ID和名称的新行。
@repeatWithIndex(computerForm("customObjects"), min = 5) { (lineorder, index) =>
@objectRow(index, lineorder, false)
@(skuCounter+=1)
}
@objectRow(id: Int, lineorder: Field, hide: Boolean) = {
<td width="3%">@inputText1(lineorder("parentName"), "input-large") </td>
<td width="10%">@inputText1(lineorder("name"), "input-medium") </td>
<td width="10%">@inputText1(lineorder("field"), "input-medium") </td>
<td width="10%">
@defining(lineorder("type")) { uidField =>
<input type="text" class=" content-box typeahead input-medium" name="@uidField.name"
value="@uidField.value" data-provide="typeahead" autocomplete="off"
data-source='["email", "digits", "number", "date", "block"]'>
}</td>
<td width="15%">@inputText1(lineorder("regrep"), "content-box input-large")</td>
<td width="15%">@inputText1(lineorder("exclude"), "content-box input-large")</td>
<td>
@if(id <= 10) {
<a href="#lsRet" onclick="addRow('orow', @(id + 1))"><i class="icon-plus"></i></a>
}
@if(id > 1) {
<a href="#lsRet" onclick="hideRow('orow', @(id))" title="Pattern"><i class="icon-minus"></i></a>
}
</td>
</tr>
}
inputText1生成以下HTML代码: <input class="content-box input-xs" name="nodes[5].order" value="5" type="text">
我想将节点索引(5)更新为下一个索引。
好吧,我假设您的代码可以正常工作,并且您只想使用jQuery将具有下一个索引值的新行添加到表中。
首先,您需要从表中获取最新索引。您可以通过<tr>
使用jQuery length检查表中已经存在的行数来获取此值。
temp = $("#table_id tr").length;
如果起始索引为1,则需要在长度值上加1。
temp = $("#table_id tr").length + 1;
然后,您可以使用.append()在temp
当前HTML中添加带有下一个索引(在变量中)的新HTML标签。
$("#table_id").append('<input class="content-box input-xs" name="nodes['+temp+'].order" value="5" type="text">');
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句