2010-09-07 82 views
1

我有一個控制器和一個gsp。我繼續嘗試構建項目,但在我的gsp上收到問題。Grails自定義服務器頁面(自定義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> 

不允許我用「它」這樣呢?還是有什麼明顯的我失蹤了?

+1

因爲你是剛剛開始,我會建議開始www.grails.org – 2010-09-07 23:48:04

+1

但你說得對。你不能用「它 - >」,但如果你省略'它 - >'我相信它會起作用 - 但它並不是真正的Groovy/Grails做法! – sbglasius 2010-09-08 09:54:28

回答

2

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> 
+0

感謝您提供非常快速的回覆。我會做更多的閱讀。你能給我一個簡單的解釋,爲什麼像這樣:<%bookList.each {它 - >%>不起作用? bookList中有一些我不需要的信息,這就是爲什麼我選擇迭代並獲取所需內容的原因。我買了Groovy Recipes這本書來學習,但作者承擔了基本的知識。 (我一直在閱讀一些Grails) – StartingGroovy 2010-09-07 23:54:52

+0

我會推薦Grails和Grails在行動的權威指南,他們都是優秀的書籍 – 2010-09-07 23:56:44

+1

提供的解決方案可以讓你挑選出你需要的......也是我相信「它」在默認情況下......如果有幫助請標記爲正確答案,這將鼓勵更多人回答您的問題。在StackOverflow中有豐富的知識,所以最好在發佈問題之前在這裏搜索 – 2010-09-07 23:59:14