【问题标题】:How to get properties of association object in Alfresco using json.ftl如何使用 json.ftl 在 Alfresco 中获取关联对象的属性
【发布时间】:2014-02-27 14:29:34
【问题描述】:

我有一个类型 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 获取关联对象的属性?

我试图获取如下关联的属性,但得到“处理模板时出错'Expression result.assocs[\"abc:nextAppDate\"] 未定义”

<#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>

【问题讨论】:

  • 很抱歉,如果您已经想到这一点,但您是否验证了您正在测试的节点实际上至少具有这些关联之一,并且它是使用正确的 qname 创建的?
  • 你说得对,杰夫。我为测试创建的两个节点之一没有关联:) 所以,我所做的是添加代码来检查“result.assocs [”abc:nextAppDate“]”是否为空,如下面我自己的答案所示。

标签: javascript json alfresco freemarker alfresco-share


【解决方案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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多