如何将记录加载到Grails组合框(见下面的截图)。
def bookList = Book.getAll();
现在如何在组合框中显示上述图书清单?
答案 0 :(得分:0)
一旦您的GSP模型中有bookList
,这是微不足道的。
假设控制器动作如下:
class MyController {
def index() {
def bookList = Book.getAll()
render(view: 'index', model: [bookList: bookList])
}
}
这样的域名:
class Book {
String title
}
您可以使用GSP中的g:select标记进行渲染,如下所示:
<g:select from="${bookList}" optionKey="id" optionValue="title" />