【问题标题】:How would I use button in the following situation in grails?在 grails 的以下情况下,我将如何使用按钮?
【发布时间】:2013-05-21 14:47:14
【问题描述】:

我正在返回一个包含多个项目的地图值。地图如下:

def myList = []

//Some code to obtain the List

List << ["Id": Id,"Name": Name,"Code": sCode, "RunType": x ]
return [items: List]

在我的 GSP 页面中,我使用以下代码将它们打印到我的网页中。

            <%
            def counter = 0

            for (i in items) {
                counter = counter + 1

                println("<td>" + i + "</td>" + "\n")

                if (counter == 1) {
                    println("</tr><tr>")
                    counter = 0
                }
            }

        %>

输出如下:

[Id:i-d0f5, Name:es_test_1b_110.test.com, Code:16, RunType:On Demand]
[Id:i-7890, Name:namc-qc.test.com, Code:16, RunType:On Demand]
[Id:i-ee56, Name:abcdef.test.com, Code:16, RunType:On Demand]
[Id:i-c41e, Name:backup.grails.test.com, Code:80, RunType:On Demand]

我现在需要为每个打印的值添加一个按钮(因此,如果打印 6 个服务器,将显示 6 个按钮,如果打印 10 个服务器,将显示 10 个按钮)我将使用该按钮通过用于启动和停止服务器的 Id。

【问题讨论】:

    标签: grails button view controller


    【解决方案1】:

    Grails 有一些强大的内置 GSP 标签,在这里非常方便。例如:

    <g:each in="${items}" var="i">
      <tr>
        <td>${i.Id}</td>
        <td>${i.Name}</td>
        <td>${i.Code}</td>
        <td>${i.RunType}</td>
        <td><a class="button" href="${createLink(controller: '<controllerName>', action: 'start', id: i.Id)}">Start</a></td>
      </tr>
    </g:each>
    

    当然,还有很多其他方法可以解决这个问题,但我希望这是一个开始。有关更多信息,请参阅 Grails 参考文档中的这些部分:eachcreateLink

    【讨论】:

    • 我的 id、Name、Code 和 RunType 没有得到解决。任何想法为什么?
    • +1 @Andrew。测试用户:您可能会看到它们在 IDE 中未解决,但如果您对其进行测试或运行它,您应该能够看到预期的结果。
    猜你喜欢
    • 2016-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-22
    • 2014-01-14
    • 1970-01-01
    相关资源
    最近更新 更多