如何使用json.ftl获取Alfresco中关联对象的属性

时间:2014-02-27 14:29:35

标签: javascript json alfresco freemarker alfresco-share

我有一个类型abc:appDate。它有一个属性abc:dateTime与self的关联,即

<association name="abc:nextAppDate">
<title>Next App Date</title>
<source>
    <mandatory>false</mandatory>
    <many>false</many>
</source>
<target>
    <class>abc:appDate</class>
    <mandatory>false</mandatory>
    <many>true</many>
</target>
</association>

如何使用json.ftl获取关联对象的属性?

我试图获取关联属性,如下所示,但在处理模板时遇到错误&#39;表达式result.assocs [\&#34; abc:nextAppDate \&#34;]是未定义&#34;

<#macro dateFormat date>${date?string("dd MMM yyyy")}</#macro>
    <#escape x as jsonUtils.encodeJSONString(x)>
    {
        "nodeRef": "${result.nodeRef}", 
        "date": "<@dateFormat result.properties["abc:dateTime"] />",
        "nextDate": [
        <#list result.assocs["abc:nextAppDate"] as childKey>
        {
        "date": "<@dateFormat childKey.properties["abc:dateTime"] />"               
        }
        <#if child_has_next>,</#if>
        </#list>
        ]
    }
    </#escape>

1 个答案:

答案 0 :(得分:1)

实际上代码需要空检查。以下代码正在运行

<#macro dateFormat date>${date?string("dd MMM yyyy")}</#macro>
    <#escape x as jsonUtils.encodeJSONString(x)>
    {
        "nodeRef": "${result.nodeRef}", 
        "date": "<@dateFormat result.properties["abc:dateTime"] />",
        "nextDate": [
        <#if (result.assocs["abc:nextAppDate"])??>
        <#list result.assocs["abc:nextAppDate"] as childKey>
        {
        "date": "<@dateFormat childKey.properties["abc:dateTime"] />"               
        }
        <#if child_has_next>,</#if>
        </#list>
        <#else>
    </#if>
        ]
    }
    </#escape>