【问题标题】:Using jopendocument with coldfusion/railo, how to add table row?将jopendocument与coldfusion / railo一起使用,如何添加表格行?
【发布时间】:2017-10-31 22:01:51
【问题描述】:

我正在使用 jopendocument 1.2 和 Railo 3.3.1.000

来自http://www.jopendocument.org/start_text_2.html

List<Map<String, String>> months = new ArrayList<Map<String, String>>();
months.add(createMap("January", "-12", "3"));
months.add(createMap("February", "-8", "5"));
months.add(createMap("March", "-5", "12"));
months.add(createMap("April", "-1", "15"));
months.add(createMap("May", "3", "21"));
template.setField("months", months);

如何在 cfml 中编写该代码,或者任何有 jopendocument 经验的人使用 cfml 在 odt 模板文件中添加行?

【问题讨论】:

    标签: coldfusion railo opendocument


    【解决方案1】:

    List<Map<String, String>> months = new ArrayList<Map<String, String>>();

    在 CF 术语中,该代码创建了一个结构数组。因为 java 是强类型的,所以代码使用泛型来指示每个对象包含什么类型的对象

        List< Map<...> >          // Array containing structures 
        Map< String, String >     // Structure containing "String" values
    

    幸运的是,CF 数组内部是 java.util.List 对象,结构是 java.util.Map 对象。因此,您只需要使用正确的键和值创建一个结构的 CF 数组。然后将数组传入template.setField(...)

    我不确定在结构中使用哪些键,所以我从jOpenDocument-template-1.2.zip 下载了“test.odt”模板。它显示每个结构应包含三 (3) 个键,表中的每一列一个键:nameminmax。只要您使用 strings 填充结构,这应该可以工作:

    // Create an array of structures. Each structure represents a table row. 
    // The key names for columns 1-3 are: "name", "min", "max"
    months = [
                {name="January", min="-12", max="3"}
                , {name="February", min="-8", max="5"}
                , {name="March", min="-5", max="12"}
                , {name="April", min="-1", max="15"}
                , {name="May", min="3", max="21"}
                , {name="June", min="5", max="32"}
            ];  
    
    // populate table rows
    template.setField("months", months);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-05-07
      • 1970-01-01
      • 2015-10-31
      • 2016-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多