【发布时间】:2014-11-25 00:48:52
【问题描述】:
我有一个 Grails (2.4.3) 应用程序,其中 GSP 页面中有一个表,该表需要根据按钮单击来填充。单击按钮时,它将向控制器传递一个 id,并根据该数字进行搜索。
普惠制:
<table id="availUsers">
<thead>
<tr>
<th class="sortable"><g:message code = '' default = 'Name'/></th>
<th class="sortable"><g:message code = '' default = 'Age'/></th>
<th class="sortable"><g:message code = '' default = 'Status'/></th>
</tr>
</thead>
<tbody>
<g:each in="${sortedListUser}" status="i" var="user">
<tr class="${(i % 2) == 0 ? 'even' : 'odd'}">
<td>${fieldValue(bean: user, field: "Name")}</g:link></td>
<td>${fieldValue(bean: user, field: "Age")}</td>
<td>${fieldValue(bean: user, field: "Status")}</td>
</tr>
</g:each>
</tbody>
</table>
JavaScript:
$("#idText").click(function () {
id = document.getElementById("userIdText").value;
if (id) {
d = {
userID: id
};
$.ajax({
type: "POST",
url: "${createLink(action:'searchUsers', controller:'CustomerSupport')}",
data: d,
async: false,
dataType: 'text',
cache: false,
success: function(result) {
if(result =='success') {
// To DO
} else {
$(".error").html(result);
}
}
});
}
});
控制器:
@Transactional
def searchUsers (CustomerSupport customerSupportInstance, long userID) {
String id = params.userID;
customerSupportInstance.sortedListUser = UserList.findAllByStatus(id);
if (customerSupportInstance.sortedListUser.size <= 0) {
render "failed"
}
else {
render "success"
}
}
如您所见,我还没有到更新/绘制表格行的地步。
如果您查看 JavaScript 部分,则在
if(result =='success') {
// To DO
}
这是我希望添加一些代码来更新表格行的地方。表格的初始视图是它只有标题,没有行。
请告诉我如何更新/填充表格行。我上面发布的所有代码都在工作!
提前感谢您的帮助!
【问题讨论】: