Grails Master-Detail 如何从表单进行管理

问题描述 投票:0回答:1

阅读使用 Grails 时的主从结构非常令人困惑。 我认为用数据库术语理解它没有问题,但是对于 grails 中的模型来说...... 我最多希望使用一种表单来创建主表单并重定向到编辑表单,我可以在其中添加新的详细记录并将其显示为底部的列表。 在编辑表单中,我单击一个链接,打开详细信息的创建表单,在其中输入数据并保存数据,然后返回到编辑表单,同时使用包含新详细信息的行进行更新。

我在谷歌上搜索了很多,但找不到任何可以帮助我理解应该如何编写控制器来管理它的内容。 当您完成一次后,这可能非常简单,所以我希望我能在这里得到一些帮助。

forms grails master-detail
1个回答
0
投票

基本上,这更多的是一个格式化 javascript 问题,它确实绑定到 grails 中。

您想要的是一个页面上有两个选项卡,因此要求

jquery
jquery-ui

如果您正在运行包含 bootstrap 的更高版本的 grails,请在

assets/javgascripts/application.js
中包含 jquery-ui 行预引导行,否则您的 ui-tabs 将无法工作

assets/css/application.css

*= require bootstrap
*= require jquery-ui-1.9.2.custom.min

javascripts/application.css

//= require jquery-ui-1.9.2.custom.min
//= require bootstrap

有了这个设置,你现在就可以使用 jquery ui 了

现在您需要在 gsp 中创建两个选项卡:

<!-- first tab at top -->
<div id="myTabs">
    <ul id="topTab">
        <li class="topLi"><a name="#mainTab" >
            <g:message code="mainForm.label"/></a></li>
<li class="topLi"><a name="#mainTab1" >
            <g:message code="anotherTab.label"/></a></li>
        /span></a></li>
    </ul>
    <div id="bottomSection">
        <div id="#mainTab1">
            <g:render template="/path/toMainForm"/>
            <div class="clearfix"></div>
        </div>
        <div id="#mainTab1">
            <g:render template="/maybe/another/form"/>
            <div class="clearfix"></div>
        </div>
    </div>
</div>
<!-- 2nd tabs at bottom -->
<div id="myTabs2">
    <ul id="botTab">
    <!-- make correct url to show all records for the child return that as a template that then renders below -->
       <li class="topTab2A"><a name="#resetPass" href='${createLink(controller:'myController',action:'showChild',)}'>
            <g:message code="reset.password"/></a></li>
<!--3rd tab on page declaration box where above li click will end url on either way not really needed it auto generates content li for above url-->
<ul id="ui-tabs-3" class="property-list"></ul>
    </ul>

<script>
    $('#myTabs,#myTabs2').tabs();
</script>

使用选项卡时,请务必确保您的 div 正确关闭,否则页面将无法正确加载

顶部的第一个选项卡将加载到模板中,其中应包含您的主表单。

底部选项卡是动态选项卡,默认情况下会加载我认为 li 的内容如果没有单击,将会操作 li href 并动态加载其下面的容器中的内容....

然后,您需要研究如何在需要时在给定选项卡上自动加载等。

您还可以使用动态加载到 div 中的 ajax 表单方法。这个示例项目进入实时表单,但不是您真正要求的。

除了为这样的问题编写代码之外,我认为还需要更多的研究实施以及来自那里的问题

给你一个想法来玩一下

© www.soinside.com 2019 - 2024. All rights reserved.