【问题标题】:How to get property of parent node's parent node如何获取父节点的父节点的属性
【发布时间】:2022-07-01 06:03:28
【问题描述】:

我正在使用 Groovy 控制台,需要通过页面标题中的值更新页面上的标题组件

getNode(\'/content/\').recurse { resourceNode ->
        if (resourceNode.hasProperty(\'sling:resourceType\')) {
            final def resourceType = resourceNode.getProperty(\'sling:resourceType\').string
            if (resourceType.equals(\'components/title\')) {
                resourceNode.setProperty(\'jcr:title\', resourceNode.parent().parent().getProperty(\'jcr:title\')) <-problem with this line
                resourceNode.save();
            }
        }
    }

我需要两个节点以上的值

我有一个例外:

groovy.lang.MissingMethodException:没有方法签名:org.apache.jackrabbit.oak.jcr.session.NodeImpl.parent() 适用于参数类型:() 值:[]

感谢帮助

    标签: groovy aem groovy-console


    【解决方案1】:

    搜索javadoc org.apache.jackrabbit.oak.jcr.session.NodeImpl

    -> https://jackrabbit.apache.org/oak/docs/apidocs/org/apache/jackrabbit/oak/jcr/session/NodeImpl.html

    NodeImpl 类中没有parent() 方法

    但是有getParent() 方法

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-29
      相关资源
      最近更新 更多