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

Javascript 如何使用json.ftl在Alfresco中获取关联对象的属性,javascript,json,alfresco,freemarker,alfresco-share,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

我有一个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>

下一个应用程序日期
假的
假的
abc:appDate
假的
真的
如何使用json.ftl获取关联对象的属性?

我试图获取关联的属性,如下所示,但获取“处理模板的表达式结果时出错。assocs[\“abc:NEXTAPDATE\”]未定义”

${date?字符串(“dd-MMM-yyyy”)}
{
“nodeRef”:“${result.nodeRef}”,
“日期”:“日期”,
“下一日期”:[
{
“日期”:”
}
,
]
}

实际上,代码需要一个空检查。下面的代码正在运行

<#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>
${date?字符串(“dd-MMM-yyyy”)}
{
“nodeRef”:“${result.nodeRef}”,
“日期”:“日期”,
“下一日期”:[
{
“日期”:”
}
,
]
}

很抱歉,如果您已经想到了这一点,但是您是否验证了您正在测试的节点实际上至少有一个关联,并且它是使用正确的qname创建的?您是对的。我为测试创建的两个节点中的一个没有关联:),因此,我添加了代码来检查“result.assocs[“abc:nextapdate”]”是否为空,如下面我自己的答案所示。
<#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>