我有一个包含 ag:each 的模板,它以表格格式呈现一组搜索结果,如下所示:
<g:if test="${company}">
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<th class="small"><g:message code="Company Name"/></th>
<th class="medium"><g:message code="TDCID"/></th>
<th class="tiny"><g:message code="STREET"/></th>
</tr>
</thead>
<tbody>
<g:each in="${company}" status="idx" var="PNo">
<tr>
<td>
<a: href="javascript:void(0)" onClick="javascript:asd();" params="[tdc:PNo.tdcId,companyid:PNo.companyId,companytype:PNo.companyType]">//params: passing not working now.Have to pass the tdcId,companyId,companyType of clicked result
${PNo.officialName}
</a:>
</td>
<td>
${PNo.tdcId}
</td>
<td>
${PNo.street}
</td>
</tr>
</g:each>
</tbody>
</table>
</g:if>
我需要将用户单击的公司对象中包含的 tdcId、companyId、companyType 传递给以下 JavaScript 函数:
function asd(){
window.open("${g.createLink(controller: 'Customer', action: 'showcontacts',params:'[tdc:company.tdcId,companyid:company.companyId,companytype:company.companyType]')}",'', 'width=200,height=100');
}
从 asd() 我需要将参数传递给 action:'showcontacts' 通过 createLink 标签。这样做的正确方法是什么?
这是调用 gsp:_customers.gsp:
<script type="text/javascript">
function asd(tdcId, companyId, companyType) {
alert(tdcId);
var link = "${g.createLink(controller: 'Customer', action: 'showcontacts')}?tdc=" + tdcId + "&companyid=" + companyId + "&companytype=" + companyType;
window.open(link, '', 'width=200,height=100');
}
</script>
<div class="form-edit">
<div class="heading">
<strong>
<g:message code="Firm Profile"/>
</strong>
</div>
<div id="hai" class="form-hold">
<g:form name="company-edit-form" action="save">
<fieldset>
<div class="form-columns">
<div class="column">
<g:applyLayout name="form/input">
<content tag="label"><g:message code="Company Name"/</content>
<content tag="label.for">Company</content>
<g:textField class="field" name="Company" id="Company" />
</g:applyLayout>
<g:applyLayout name="form/checkbox">
<content tag="label"><g:message code="Starts with"/</content>
<content tag="label.for">Starts with</content>
<g:checkBox class="cb checkbox" name="StartsWith" />
</g:applyLayout>
<g:applyLayout name="form/input">
<content tag="label"><g:message code="Street"/></content>
<content tag="label.for">Street</content>
<g:textField class="field" name="Street" />
</g:applyLayout>
<g:applyLayout name="form/checkbox">
<content tag="label"><g:message code="Starts with"/</content>
<content tag="label.for">Starts With</content>
<g:checkBox class="cb checkbox" name="StreetStartsWith"/>
</g:applyLayout>
<g:applyLayout name="form/input">
<content tag="label"><g:message code="Zip code"/></content>
<content tag="label.for">Zip</content>
<g:textField class="field" name="ZipCode"/>
</g:applyLayout>
<g:applyLayout name="form/input">
<content tag="label"><g:message code="Fagrubrik"/</content>
<content tag="label.for">Fagrubrik</content>
<g:textField class="field" name="Fagrubrik" />
</g:applyLayout>
<g:applyLayout name="form/input">
<content tag="label"><g:message code="House no."/</content>
<content tag="label.for">HouseNo</content>
<g:textField class="field" name="HouseNo" />
</g:applyLayout>
<g:applyLayout name="form/input">
<content tag="label"><g:message code="Tel./Fax."/</content>
<content tag="label.for">Telephone</content>
<g:textField class="field" name="Telephone" />
</g:applyLayout>
<g:applyLayout name="form/input">
<content tag="label"><g:message code="Company No."/</content>
<content tag="label.for">CompanyNo</content>
<g:textField class="field" name="CompanyNo" />
</g:applyLayout>
<g:applyLayout name="form/input">
<content tag="label"><g:message code="City"/></content>
<content tag="label.for">City</content>
<g:textField class="field" name="City" />
</g:applyLayout>
<g:applyLayout name="form/input">
<content tag="label"><g:message code="TDC ID"/></content>
<content tag="label.for">TdcId</content>
<g:textField class="field" name="TdcId" />
</g:applyLayout>
<g:applyLayout name="form/input">
<content tag="label"><g:message code="Industry Designation"/></content>
<content tag="label.for">Industry Designation</content>
<g:textField class="field" name="IndustryDesignation" />
</g:applyLayout>
<g:applyLayout name="form/input">
<content tag="label"><g:message code="Decision Maker"/</content>
<content tag="label.for">DecisionMaker</content>
<g:textField class="field" name="DecisionMaker" />
</g:applyLayout>
<g:applyLayout name="form/input">
<content tag="label"><g:message code="Email"/></content>
<content tag="label.for">Email</content>
<g:textField class="field" name="Email" />
</g:applyLayout>
<g:applyLayout name="form/input">
<content tag="label"><g:message code="WWW"/></content>
<content tag="label.for">WWW</content>
<g:textField class="field" name="WWW"/>
</g:applyLayout>
</div>
</div>
<div>
<br/>
</div>
<div id="button" class="buttons">
<ul>
<li>
<g:submitButton class="buttons" id="button" name="Search"
value="Search" action="search"/>
</li>
</ul>
</div>
</fieldset>
</g:form>
<div class="table-box">
<g:if test="${company}"><table cellpadding="0" cellspacing="0">
<thead>
<tr>
<th class="small"><g:message code="Company Name"/></th>
<th class="medium"><g:message code="TDCID"/></th>
<th class="tiny"><g:message code="STREET"/></th>
</tr>
</thead>
<tbody>
<g:each in="${company}" status="idx" var="PNo">
<tr>
<td>
<a href="javascript:void(0)"
onClick="javascript:asd('${PNo.tdcId}','${PNo.companyId}',
'${PNo.companyType}');">${PNo.officialName}</a>
</td>
<td>
<g:remoteLink action="show" id="${PNo}" before="register(this);"
onSuccess="render(data, next);" params="[template:'show']">
${PNo.tdcId}
</g:remoteLink>
</td>
<td>
${PNo.street}
</td>
</tr>
</g:each>
</tbody>
</table>
</g:if>
</div>
</div>
</div>
这是为测试目的而调用的。命名为 _showcontacts.gsp:
<body>
<div id="dialog" title="Contacts">
hai
</div>
</body>