问题描述
具体是如何使用 JavaScript 获取子节点内容的?
How do you get child node content with JavaScript specifically?
我可以使用以下方法获取父节点信息:
I am able to get the parent node information by using the following:
granite.resource.properties
granite.resource.properties
但是我需要访问子节点
-父
-- 子(命名图像)
有多种方法可以使用 Java 访问子节点,但我正在构建仅使用 JavaScript 的解决方案:
There are ways to get access to the child node with Java but I am building a JavaScript only solution:
下面的 Java 示例
Java Example below
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");
推荐答案
使用 AEM 附带的图像基础组件有助于获得有关如何访问数据的指导.对我来说,只需进行一些修改并使其按预期工作即可.您可以在此处找到 AEM 图像组件:
Using the image base component that comes with AEM helps get guidance on how to access te data. For me it was just a matter to make some modifications and have it working as expected. You can find the AEM image component here:
/libs/wcm/foundation/components/image/
/libs/wcm/foundation/components/image/
浏览提供的不同文件以获取更多信息.
Browse through the different files provided to get more info.
这篇关于AEM 获取子节点内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!