【问题标题】:Grails custom server page (custom gsp)Grails 自定义服务器页面(自定义 gsp)
【发布时间】:2010-09-07 23:42:18
【问题描述】:

我有一个控制器和一个 gsp。我继续尝试构建项目,但在我的 gsp 上收到问题。

它告诉我“当前作用域已经包含一个名为它的变量”

<html>
  <head>
    <title>Book Collector</title>
    <meta name="layout" content="main" />
  </head>
  <body>
    <h1>Book Editor</h1>
    <table>
      <tr>
        <th>Book Name</th>
        <th>Author</th>
        <th>Page Number</th>
        <th>Vendor</th>
        <th>Date Scanned</th>
        <th>Date Read</th>
      </tr>
      <% bookList.each { it -> %>
      <tr>
        <td><%= it.bookName %></td>    //this is where the error starts
        <td><%= it.author %></td>      //error (it)
        <td><%= it.pageNumber %></td>  //error (it)
        <td><%= it.lastScan %></td>    //error (it)
        <td><%= it.lastRead %></td>    //error (it)
        <% } %>
      </tr>
    </table>
  </body>
</html>

我不能这样使用“它”吗?还是有什么明显的我遗漏的东西?

【问题讨论】:

  • 因为您刚刚开始,我建议您从 www.grails.org 开始
  • 但你是对的......你不能使用'it ->',但如果你省略'it ->',我相信它会起作用 - 但它不是真正的 Groovy/Grails 方式这样做!

标签: grails groovy gsp


【解决方案1】:

http://www.grails.org/Views+and+Layouts

<html>
<head>
    <title>Book list</title>
</head>
<body>
<h1>Book list</h1>
<table>
    <tr>
        <th>Title</th>
         <th>Author</th>
    </tr>
    <g:each in="${books}">
        <tr>
             <td>${it.title}</td>
             <td>${it.author}</td>
        </tr>
    </g:each>
</table>
</body>
</html>

【讨论】:

  • 感谢您的快速回复。我会做更多的阅读。你能给我一个简短的解释为什么这样的事情: %> 不起作用? bookList 中有一些我不需要的信息,这就是我选择迭代并获取我想要的内容的原因。我买了一本书 Groovy Recipes 来学习,但作者假设有基本知识。 (与此同时,我一直在阅读一些 grails)
  • 我会推荐 The Definitive Guide to Grails & Grails in Action,它们都是优秀的书籍
  • 所提供的解决方案让您可以挑选出您需要的东西......我相信“它”默认就在那里......如果有帮助,请将答案标记为正确,它将鼓励更多人来回答你的问题。 StackOverflow 里面有丰富的知识,所以最好在发问题之前在这里搜索一下
  • 谢谢 Aaron,有推荐的 Groovy 书籍吗? (Groovy 食谱做得很好,但并没有涵盖所有内容)
  • Groovy in Action 的第一版是一本很棒的书,但现在已经过时了。我会等第二版。我认为它目前以“测试版”格式的电子书形式提供。
猜你喜欢
  • 2021-06-08
  • 1970-01-01
  • 2016-09-02
  • 2021-07-06
  • 2011-02-28
  • 1970-01-01
  • 2016-09-25
  • 2022-07-13
  • 2017-07-27
相关资源
最近更新 更多