Grails GSP循环遍历索引,并对选定的行进行处理 [英] Grails GSP Loop through an index and do somthing with selected lines
问题描述
在Index-gsp中,我希望能够选择任意数量的行,然后通过单击链接将所有这些行发送到控制器进行处理,例如创建不同种类的新对象.
In an Index-gsp, I want to be able to select an arbitrary number of lines and then by clicking a link send all those lines to a controller for processing e.g. creating new objects of a different kind.
我不知道如何进行选择或如何在GSP中收集这些选定的行.可能的话,也许我应该在每行上使用一个复选框?
I've no idea how selection can be done or how to collect these selected lines in a GSP. Maybe I should use a checkbox on each line if that's possible?
这是使用修改后的index.gsp显示的产品列表. 每个产品线前面都有一个复选框. 我想要的是列出要检查的产品,然后将此列表发送给控制器.
It's a list of products which is displayed using a modified index.gsp. Each product-line has a checkbox in front. What I want is to make a list of the products that are checked an then transmit this list to a controller.
此index.gsp的一部分:
a part of this index.gsp:
<li><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></li>
<li><g:link class="create" action="create"><g:message code="default.new.label" args="[entityName]" /></g:link></li>
<li><g:link class="create" action="createOffer"><g:message code="default.new.label" args="[entityName]" params="toOffer" /></g:link></li>
</ul>
</div>
<div id="list-prodBuffer" class="content scaffold-list" role="main">
<h1><g:message code="default.list.label" args="[entityName]" /></h1>
<g:if test="${flash.message}">
<div class="message" role="status">${flash.message}</div>
</g:if>
<table>
<thead>
<tr>
<td> Välj</td>
<td> ID</td>
</tr>
</thead>
<tbody>
<g:each in="${prodBufferList}" status="i" var="prodBuffer">
<tr class="${ (i % 2) == 0 ? 'even': 'odd'}">
<td><g:checkBox name="toOffer" value="${prodBuffer.id}" checked="false" /></td>
<td>${prodBuffer.id}</td>
所以这不是普通形式,只是我想使用链接将其传输到控制器的列表.
So this not an ordinary form, just a list where I want to use a link to transmit it to the controller.
我是一个初学者,不知道如何做.
I'm a beginner and have no idea how to do it.
推荐答案
您可以使用javascript从页面收集所有必要的数据,然后将所有数据发送到控制器进行处理. 有很多方法可以做到这一点. 例如通过JQuery发送:
You can collect all necessary data from page using javascript, and then send all data to your controller for processing. There are a lot of ways to do it. For example send via JQuery:
<script>
//some code
var items = [1,2,3];
//some code
$('#add-location').click(function () {
$.ajax({
type: "POST",
url: "${g.createLink(controller:'myController', action: 'myControllerMethod')}",
data: {items: items},
success: function (data) {
console.log(data)
}
});
});
</script>
这篇关于Grails GSP循环遍历索引,并对选定的行进行处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!