AEM 获取 child 节点内容
AEM Get child node content
如何使用 Java 脚本获取 child 节点内容?
我可以使用以下方法获取 parent 节点信息:
granite.resource.properties
但是我需要访问 child 节点
-parent
-- child(命名图像)
有一些方法可以使用 Java 访问 child 节点,但我正在构建一个 Java 仅脚本解决方案:
Java 下面的例子
for (Node n1 : JcrUtils.getChildNodes(node)){
String imagePath = n1.getPath().toString();
Resource imageResource = resourceResolver.getResource(imagePath);
Node imageNode = imageResource.adaptTo(Node.class);
ValueMap imageNodeProps = imageResource.adaptTo(ValueMap.class);
String imageName = null;
imageName= imageNodeProps.get("fileReference", "None");
我不知道如何获取子节点属性,但也许我遇到了类似的问题,因为我想在组件中使用图像。我试图将图像设置为子节点,但没有用,因为我不知道如何访问它。
我最终是使用 css.
加载图像
使用 AEM 附带的图像基础组件有助于获得有关如何访问 te 数据的指导。对我来说,只需进行一些修改并使其按预期工作即可。您可以在此处找到 AEM 图像组件:
/libs/wcm/foundation/components/image/
浏览提供的不同文件以获取更多信息。
您可以在代码之间使用 console.log()
并检查 error.log
中的值
function(nodeInfo) {
/* from current node, get the children nodes */
nodeInfo.childrenNodes = currentNode.getNodes();
if(typeof nodeInfo.childrenNodes != "undefined") {
for(var childrenNode in nodeInfo.childrenNodes) {
/*iterate through children nodes, get specific 'child' node */
if(childrenNode === "specificChildNode") {
/* if required property is present, get that property */
if(nodeInfo.childrenNodes[childrenNode].hasProperty("requiredProperty")){
nodeInfo.reqProp = nodeInfo.childrenNodes[childrenNode].getProperty("requiredProperty");
}
}
}
}
return nodeInfo;
};
如何使用 Java 脚本获取 child 节点内容?
我可以使用以下方法获取 parent 节点信息:
granite.resource.properties
但是我需要访问 child 节点
-parent
-- child(命名图像)
有一些方法可以使用 Java 访问 child 节点,但我正在构建一个 Java 仅脚本解决方案:
Java 下面的例子
for (Node n1 : JcrUtils.getChildNodes(node)){
String imagePath = n1.getPath().toString();
Resource imageResource = resourceResolver.getResource(imagePath);
Node imageNode = imageResource.adaptTo(Node.class);
ValueMap imageNodeProps = imageResource.adaptTo(ValueMap.class);
String imageName = null;
imageName= imageNodeProps.get("fileReference", "None");
我不知道如何获取子节点属性,但也许我遇到了类似的问题,因为我想在组件中使用图像。我试图将图像设置为子节点,但没有用,因为我不知道如何访问它。 我最终是使用 css.
加载图像使用 AEM 附带的图像基础组件有助于获得有关如何访问 te 数据的指导。对我来说,只需进行一些修改并使其按预期工作即可。您可以在此处找到 AEM 图像组件:
/libs/wcm/foundation/components/image/
浏览提供的不同文件以获取更多信息。
您可以在代码之间使用 console.log()
并检查 error.log
function(nodeInfo) {
/* from current node, get the children nodes */
nodeInfo.childrenNodes = currentNode.getNodes();
if(typeof nodeInfo.childrenNodes != "undefined") {
for(var childrenNode in nodeInfo.childrenNodes) {
/*iterate through children nodes, get specific 'child' node */
if(childrenNode === "specificChildNode") {
/* if required property is present, get that property */
if(nodeInfo.childrenNodes[childrenNode].hasProperty("requiredProperty")){
nodeInfo.reqProp = nodeInfo.childrenNodes[childrenNode].getProperty("requiredProperty");
}
}
}
}
return nodeInfo;
};