【问题标题】:Grails: How to pass arrays to GSP pagesGrails:如何将数组传递给 GSP 页面
【发布时间】:2009-04-24 16:54:26
【问题描述】:

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

这是我下面的示例代码。

         File dir = new File(petl_dir_path)
          def list= []                      
          dir.eachDir{ list << it.name }       

请指导

谢谢

【问题讨论】:

    标签: grails


    【解决方案1】:

    您的“列表”不是数组,它是 ArrayList 的一个实例。但是,您可以简单地将其传递给您的视图(在以下示例中,我假设您有 index 操作),例如:

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

    然后您可以在 GSP 中处理“目录”。

    【讨论】:

    • 为什么要将列表强制转换为字符串数组?
    • 因为问题是关于传递数组。我还想表明他对 List 和数组的理解并不完全正确。
    猜你喜欢
    • 2012-05-31
    • 1970-01-01
    • 1970-01-01
    • 2011-10-13
    • 1970-01-01
    • 2014-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多