简体   繁体   English

Sling - 循环遍历资源的属性

[英]Sling - Loop through properties of a resource

I'm used to using nodes in sling and accustomed to looping through nodes with something like: 我习惯在吊索中使用节点,并习惯于通过节点循环,例如:

NodeIterator headerNode = currentNode.getNodes();
//loop through and do something

But how would I do this if I'm trying to loop through all the properties of a resource. 但是,如果我试图遍历资源的所有properties ,我将如何做到这一点。 I'm really lost here. 我真的迷失在这里。 So currently I'm simply grabbing a single property of a resource. 所以目前我只是抓住资源的一个属性。 But what if I want to grab all the properties of said resource how would I do that? 但是,如果我想抓住所述资源的所有属性怎么办呢?

Resource getResource = resourceResolver.getResource("/content/AboutPage/jcr:content/list");
ValueMap property = getResource.adaptTo(ValueMap.class);
String title = property.get("jcr:lastEdited", String.class);

Any help is greatly appreciated! 任何帮助是极大的赞赏!

As ValueMap extends java.util.Map you can use the entrySet() method: ValueMap扩展java.util.Map时,您可以使用entrySet()方法:

Resource getResource = resourceResolver.getResource("/content/AboutPage/jcr:content/list");
ValueMap property = getResource.adaptTo(ValueMap.class);
for(Entry<String, Object> e : property.entrySet()) {
    String key = e.getKey();
    Object value = e.getValue();
    //use the key and value here
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM