1

2 つのコントローラー Entity と EntityGlobal の間で HTML ビューを相互化しようとしています。

エンティティ コントローラ メソッドは次を示します。

public static void show(String id) {
    Object entity = entityService(id);
    renderTemplate("@detailEntity", entity);
}

EntityGlobal コントローラー メソッドの表示:

public static void show(String id) {
    Object entity = globalEntityService(id);
    renderTemplate("@detailEntity", entity);
}

実際の状況:

エンティティ コントローラの list.html を表示します。

...
<table>
#{list entities, as:'entity'}
    <tr>
    <td><a href="@{Entity.show(entity.id)}">entity.name</a></td>
    ...
    </tr>
#{/list}
</table>
...

EntityGlobal コントローラーの list.html を表示します。

...
<table>
#{list entities, as:'entity'}
    <tr>
    <td><a href="@{EntityGlobal.show(entity.id)}">entity.name</a></td>
    ...
    </tr>
#{/list}
</table>
...

次の行を除いて、すべてのコードが複製されます。

<a href="@{EntityGlobal.show(entity.id)}">

私はそのようなものを持とうとしています:

汎用テンプレート ビュー listTemplate.html :

...
<table>
#{list entities, as:'entity'}
    <tr>
    <td><a href="javascript:show('${entity.id}');">entity.name</a></td>
    ...
    </tr>
#{/list}
</table>
...

エンティティ コントローラの list.html を表示します。

#{include 'listTemplate.html' /}
<script>
    var showEntity = #{jsAction @Entity.show(':entityId') /};
    function show(entityId) {
        $.get(showEntity({entityId: entityId}), function() {console.log("entity SUCCESS");});
    }
</script>

EntityGlobal コントローラーの list.html を表示します。

#{include 'listTemplate.html' /}
<script>
    var showEntity = #{jsAction @EntityGlobal.show(':entityId') /};
    function show(entityId) {
        $.get(showEntity({entityId: entityId}), function() {console.log("entity global SUCCESS");});
    }
</script>

うまくいきません。リンクをクリックすると、メソッド @EntityGlobal.show(':entityId') が呼び出され、console.log si のメッセージが出力されましたが、ビュー 'detailEntity' のレンダリングは行われません。

jqueryでアクションプレイを呼び出してテンプレートをロードすることは可能ですか? 誰かがそれを行う方法を知っていれば、それは非常に役に立ちます。

ありがとう。

4

2 に答える 2

0
<script>
    var showEntityUrl = '@@{EntityGlobal.show(entity.id)}';
    window.location = showEntityUrl;
</script>
于 2013-05-22T19:00:36.307 に答える