我正在查看一些旧代码,并试图达到将选择的联系人实例 ID(复选框)与报告附加到将填充远程字段的选择框的目标。例如,这是传递给控制器的参数:
[id:1, reportsToResults:[x, y, z, ], reportsTo.id:[56, 55, 55], reportsTo:[id:[56, 55, 55]], contactList:[55, 57], _contactList:[, , , ], _select:, action:index, controller:tempController]
我理论上需要的是这样的东西:
contactList:[ , , 55, 57, ] (where empty spaces are checkboxes that are NOT selected.
reportsTo.id:[ , , 56, 56, ] (where empty spaces are empty selection boxes.
如何传递值数组?因为我可以传递所有contactList ID 和reportsTo.id - 但我无法根据数组槽正确匹配它们或将它们捆绑在一起。
任何的想法:?
<!doctype html>
<html>
<head>
<meta name="layout" content="main">
</head>
<body>
<div id="company-roster" class="company-roster">
<h1>${companyName} Roster</h1>
<g:form>
<g:hiddenField name="id" value="${id}" />
<div class="choicePanel">
<div class="choicePanel-reportsTo">
<label>Save all reports to additions:</label>
<g:actionSubmit value="Update Reports To" action="addReportsTo"/>
</div>
</div>
<script>
function all() {
$(':checkbox[name=select]').click (function () {
$(':checkbox[name=contactList]').prop('checked', this.checked);
});
}
</script>
<div style="position:absolute; margin-top:10px; width: 1350px; height: 650px; overflow: auto;">
<table>
<thead>
<tr>
<th><g:checkBox name="select" onclick="all();"/></th>
<g:sortableColumn property="firstName" action="roster" title="${message(code: 'contact.firstName.label', default: 'First Name')}" />
<g:sortableColumn property="lastName" action="roster" title="${message(code: 'contact.lastName.label', default: 'Last Name')}" />
<th>Reports To</th>
</tr>
</thead>
<tbody>
<g:each in="${companyRoster}" status="i" var="contactInstance">
<tr class="${(i % 2) == 0 ? 'even' : 'odd'}">
<td><g:checkBox name="contactList" value="${contactInstance.id}" checked="${false}"/></td>
<td>${fieldValue(bean: contactInstance, field: "firstName")}</td>
<td>${fieldValue(bean: contactInstance, field: "lastName")}</td>
<td>
Reports To: <g:remoteField action="getReportsToResults" controller="contact" id="" update="rtResult_${contactInstance.id}" paramName="search" name="reportsToResults" value="" />
<br/>
<g:each in ="${contactInstance?.reportsTo}" var="reportsTo" status="x">
<li style="list-style-type:none;">${reportsTo}<g:link controller="contact" action="removeReportsTo" params="${[reportsToID: reportsTo.id, contactInstanceID: contactInstance.id, comp_id:id]}">Remove</g:link></li>
</g:each>
</td>
<td>
<div id="rtResult_${contactInstance.id}" class="rtResult_${contactInstance.id}">
<g:select name="reportsTo.id" from="${rtResults}" value="" />
</div>
</td>
</tr>
</g:each>
</tbody>
</table>
</div>
</g:form>
</div>
</body>
</html>