显示Grails中组合框的记录列表

时间:2014-10-03 18:02:20

标签: grails gsp

如何将记录加载到Grails组合框(见下面的截图)。

enter image description here

def bookList = Book.getAll();

现在如何在组合框中显示上述图书清单?

1 个答案:

答案 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" />