我在Adobe6.2中有一个用于滑块的touch-ui multi-field component,我无法在保存在JCR中的多个节点上迭代,在遍历每个需要创建数组列表以在HTL中进一步使用的节点之后。
JCR节点如下所示

JAVA逻辑代码1:
public class SliderLogic extends WCMUse {
private ValueMap childProperties;
private Integer childCount;
@Override
public void activate() throws Exception {
String childNode = get("childNode", String.class);
Resource childResource = getResource().getChild(childNode);
System.out.println("childResource++++" + childResource);
if (childResource != null) {
childProperties = childResource.adaptTo(ValueMap.class);
for(Entry<String, Object> e : childProperties.entrySet()) {
String key = e.getKey();
Object value = e.getValue();
System.out.println("Elements=" + e);
System.out.println("key=" + key);
System.out.println("value=" + value);
}
}
}
public ValueMap getChildProperties() {
return childProperties;
}
}代码1的系统输出如下:
childResource++++JcrNodeResource, type=nt:unstructured, superType=null, path=/content/zero-6/en/jcr:content/content-parsys/slider/slides
Elements=jcr:primaryType=nt:unstructured
key=jcr:primaryType
value=nt:unstructuredCode2:又一次尝试,但没有运气
@Override
public void activate() throws Exception {
String childNode = get("childNode", String.class);
Resource childResource = getResource().getChild(childNode);
System.out.println("childResource++++" + childResource);
if (childResource != null) {
childProperties = childResource.adaptTo(ValueMap.class);
Iterable<Resource> getChildren = getResource().getChildren();
Iterator<Resource> children = getResource().listChildren();
System.out.println("childProperties="+childProperties);
System.out.println("getChildren="+getChildren);
while (children.hasNext()) {
Resource child = children.next();
System.out.println("child=" + child);
}
}
}用于代码2的系统:
childResource++++JcrNodeResource, type=nt:unstructured, superType=null, path=/content/zero-6/en/jcr:content/content-parsys/slider/slides
childProperties=JcrPropertyMap [node=Node[NodeDelegate{tree=/content/zero-6/en/jcr:content/content-parsys/slider/slides: { jcr:primaryType = nt:unstructured, 1 = { ... }, 2 = { ... }, 3 = { ... }, 4 = { ... }}}], values={jcr:primaryType=nt:unstructured}]
getChildren=org.apache.sling.api.resource.AbstractResource$1@34488dc4
child=JcrNodeResource, type=nt:unstructured, superType=null, path=/content/zero-6/en/jcr:content/content-parsys/slider/bannerImage
child=JcrNodeResource, type=nt:unstructured, superType=null, path=/content/zero-6/en/jcr:content/content-parsys/slider/slides用于呈现的HTL代码
<div data-sly-use.slide="${'SliderLogic' @ childNode='slides'}">
<ul data-sly-list.child="${resource.listChildren}">
<li>${child} == ${child.slideTitle || 'no title'} </li>
</ul>
</div>发布于 2018-02-12 09:27:47
假设呈现的资源对应于slider/slides,则可以使用以下HTL片段:
<ul data-sly-list.child="${resource.listChildren}">
<li>${child.properties.slideTitle || 'no title'}</li>
</ul>如果呈现的资源与此不对应,则可以利用use对象返回slides资源或直接将其子节点作为列表/迭代器返回。
https://stackoverflow.com/questions/48741445
复制相似问题