Grails:如何将数组传递给GSP页面

3 grails

我需要在GSP页面中显示目录列表.你能指导我如何将这个数组传递给GSP吗?

这是我的下面示例代码.

         File dir = new File(petl_dir_path)
          def list= []                      
          dir.eachDir{ list << it.name }       
Run Code Online (Sandbox Code Playgroud)

请指导

谢谢

cha*_*wit 6

你的'list'不是数组,它是ArrayList的一个实例.但是,您可以简单地将它传递给您的视图(在下面的示例中,我假设您有索引操作),如:

def index = {
  File dir = new File(petl_dir_path)
  def list= []                          
  dir.eachDir{ list << it.name }
  [dirs: list as String[]]
}
Run Code Online (Sandbox Code Playgroud)

然后你可以在你的GSP中处理'dirs'.