「ResultContentAsFacets」という div を持つ search.gsp という gsp ページが 1 つあります。div は別の gsp の内容を示します。この別の gsp の名前は subSearch.gsp です。このページには、アクション subSearch を呼び出して subsearch.gsp をリロードするリンクがあります。しかし問題は、search.gsp もリロードすることです。私は何をすべきか??
1 に答える
ユーザー tim_yates は基本的に正しいですが、おそらく remoteLink の代わりに formRemote が必要になるでしょう。
基本的には、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]
}
ページ全体をリロードせずに、id="ResultContentAsFacets" の div が更新されます
私の例では、ブラウザで JavaScript がオフになっているエラー ケースやユーザーは処理されません。また、検索結果にページネーションが必要な場合は、他にもやるべきことがいくつかありますが、それは可能です。また、jquery を含める必要があるのか、タグ<r:require module="jquery">
を使用する必要があるのか もわかりません。<g:formRemote>
ドキュメントで調べてください。お役に立てれば...