How to iterate over jcr nodes in specific order?

Avatar

Avatar

jezwn

Avatar

jezwn

jezwn

12-02-2020

I was working around with the iterator to list and traverse over child nodes and I'm getting this anomalous behavior where the iterator lists the nodes in different order each time. I need to iterate over nodes as it's present in the crx/de. Is there a way it could be done, to control the order of listing!

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

dvnSudheer

Avatar

dvnSudheer

dvnSudheer

13-02-2020

@jezwn, Could you please provide more information on what kind of nodes are you referring to and what is the API you are using to get the children.

 

Ideally if you use the page API, it will give the same order as it is created for the child pages, if you would like to have a different order, you can always change it from the sites console and the API will return the pages in the new order

API: page.listChildren()

Answers (1)

Answers (1)

Avatar

Avatar

Jörg_Hoh

Employee

Total Posts

3.0K

Likes

891

Correct Answer

1.0K

Avatar

Jörg_Hoh

Employee

Total Posts

3.0K

Likes

891

Correct Answer

1.0K
Jörg_Hoh
Employee

14-02-2020

Hi,

 

in JCR nodes can be of 2 types: ordered or unordered. In the case of ordered nodes child nodes are always returned in the same order. In the case of unordered nodes child nodes the order is not guaranteed.

Most types are ordered, especially when dealing in areas where order matters. In case it does not, unordered nodes can be used which can bring a performance benefit.

 

What node types are you iterating?