Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

Get List items using JS Use-api

Avatar

Level 3

I'm trying to get the list of pages that author select in component setting

snowwhite92_0-1663707389323.png

 

and sort the list by the custom date author select in item page property then display that in HTL. 

snowwhite92_1-1663707552965.png

 

Currently I'm stuck at pulling that list in JS Use-api. 

 

I have tried getting the list

var list = com.adobe.cq.wcm.core.components.models.List;
var pagesToBeListed = list.listItems;

but I get error "listItems not defined. 

 

How can I get a list of child pages, fixed list or tags in use-api so I can sort them the way I want it?

snowwhite92_3-1663707800746.png

 

 

4 Replies

Avatar

Community Advisor

Hi,

Instead of trying to sort it in frontend, you can try to sort it in sling model and form the list which can be used directly in sightly.

 

Avatar

Level 3

@Ravi_Pampana JavaScript actually get translated to Java through Rhino. It's not front-end but I agree it's better to use Sling Model but I haven't learned that part yet. 

 

Avatar

Community Advisor

Hi,

Why you need this in use api. The implementation is already done, please check below component

https://github.com/Adobe-Marketing-Cloud/aem-sample-we-retail/tree/master/ui.apps/src/main/content/j... 

 

You should use java instead for java use api, just a suggestion.

 

but still you need to write use api then you can check below

https://jimfrenette.com/aem/javascript-use-api/ 



Arun Patidar

Avatar

Level 3

@arunpatidar List is implemented but I need to change the Order by a different date property. Currently the List is Order by Last Modified Date or Title. I need to change the Order by the date author can select in page properties. I'm have code in Java for years that's why I was trying to use JS Use-api.