我有一个gsp页面,叫做search.gsp,它有一个叫做'ResultContentAsFacets‘的div。div显示另一个gsp的内容。另一个gsp被命名为subSearch.gsp。现在,在这个页面中,我有一个调用操作subSearch的链接,以便它重新加载subsearch.gsp。但问题是它也会重新加载search.gsp。我该怎么办??
发布于 2013-09-27 17:11:00
用户tim_yates基本上是正确的,但您可能需要formRemote而不是remoteLink。
基本上,您将在search.gsp中拥有(取自文档:http://grails.org/doc/latest/ref/Tags/formRemote.html,但做了一些更改)
<g:formRemote name="search"
update="ResultContentAsFacets"
method="GET"
url="[controller: 'changeThis', action: 'subSearch']">
<!-- your input/ search fields -->
</g:formRemote>
<div id="ResultContentAsFacets">
<!-- this div is updated with the result of the submit -->
<!-- you may already render subSearch.gsp on first pageload here.
Just pass all entries to the view in your search action -->
</div>在"ChangeThisController“中创建一个执行实际搜索的操作subSearch
但是,您只需呈现模板(subSearch.gsp),而不是返回结果:
def subSearch() {
// perform search and store collection in variable called "result"
// (change naming at your will)
render template: 'subSearch' model: [result: result]
}你的div id="ResultContentAsFacets“将会更新,不需要重新加载整个页面。
我的示例不处理错误情况或在浏览器中关闭了javascript的用户。如果你想在搜索结果中进行分页,还有更多的事情要做……但这是有可能的。我也不确定是否必须包含jquery或执行<r:require module="jquery">才能使用<g:formRemote>标记。在文档中查找它。希望这能帮到你。
https://stackoverflow.com/questions/18825101
复制相似问题