Get List items using JS Use-api | Community
Skip to main content
September 20, 2022

Get List items using JS Use-api

  • September 20, 2022
  • 2 replies
  • 1291 views

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

 

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

 

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?

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

Ravi_Pampana
Community Advisor
Community Advisor
September 21, 2022

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.

 

MoiezMaAuthor
September 21, 2022

@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. 

 

arunpatidar
Community Advisor
Community Advisor
September 21, 2022

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/jcr_root/apps/weretail/components/content/list 

 

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
MoiezMaAuthor
September 21, 2022

@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.