trouble accessing child nodes with .getItem

Avatar

Avatar

karlw37000147

Avatar

karlw37000147

karlw37000147

20-08-2018

hi,

as yo can see below i am getting back this data using .getItem().

everything is there but i cant seem to select the child nodes.

20.08 .2018 15: 19: 22.609 * INFO * [0: 0: 0: 0: 0: 0: 0: 1[1534774762547] GET / content / intranet / Hub.html HTTP / 1.1] apps.intranet.components.structure.mega - menu.mega - menu$html karl: com.adobe.granite.confmgr.impl.ConfImpl$ResourceNamedValueMap @192b2fbf: JcrPropertyMap[node = Node[NodeDelegate {

tree = /conf/intranet / settings / megamenu / services / jcr: content: {

jcr: primaryType = cq: PageContent,

jcr: createdBy = admin,

jcr: title = Services,

cq: lastReplicationAction = Activate,

cq: lastReplicatedBy = admin,

jcr: created = 2018 - 05 - 16 T15: 58: 06.629 + 01: 00,

cq: lastReplicated = 2017 - 03 - 01 T09: 33: 23.777 Z,

benefits = { ...

},

jobs - volunterring = { ...

},

business = { ...

},

licensing = { ...

},

your - city - council = { ...

}

}

}], values = {

jcr: primaryType = cq: PageContent,

jcr: createdBy = admin,

jcr: title = Services,

cq: lastReplicationAction = Activate,

cq: lastReplicatedBy = admin,

jcr: created = java.util.GregorianCalendar[time = 1526482686629, areFieldsSet = true, areAllFieldsSet = true, lenient = false, zone = sun.util.calendar.ZoneInfo[id = "GMT+01:00", offset = 3600000, dstSavings = 0, useDaylight = false, transitions = 0, lastRule = null], firstDayOfWeek = 2, minimalDaysInFirstWeek = 4, ERA = 1, YEAR = 2018, MONTH = 4, WEEK_OF_YEAR = 20, WEEK_OF_MONTH = 3, DAY_OF_MONTH = 16, DAY_OF_YEAR = 136, DAY_OF_WEEK = 4, DAY_OF_WEEK_IN_MONTH = 3, AM_PM = 1, HOUR = 3, HOUR_OF_DAY = 15, MINUTE = 58, SECOND = 6, MILLISECOND = 629, ZONE_OFFSET = 3600000, DST_OFFSET = 0],

cq: lastReplicated = java.util.GregorianCalendar[time = 1488360803777, areFieldsSet = true, areAllFieldsSet = true, lenient = false, zone = sun.util.calendar.ZoneInfo[id = "GMT", offset = 0, dstSavings = 0, useDaylight = false, transitions = 0, lastRule = null], firstDayOfWeek = 2, minimalDaysInFirstWeek = 4, ERA = 1, YEAR = 2017, MONTH = 2, WEEK_OF_YEAR = 9, WEEK_OF_MONTH = 1, DAY_OF_MONTH = 1, DAY_OF_YEAR = 60, DAY_OF_WEEK = 4, DAY_OF_WEEK_IN_MONTH = 1, AM_PM = 0, HOUR = 9, HOUR_OF_DAY = 9, MINUTE = 33, SECOND = 23, MILLISECOND = 777, ZONE_OFFSET = 0, DST_OFFSET = 0]

}]

any idea how to access them?

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

3.0K

Likes

1.1K

Correct Reply

840

Avatar

Arun_Patidar

MVP

Total Posts

3.0K

Likes

1.1K

Correct Reply

840
Arun_Patidar
MVP

20-08-2018

Hi,

If you copy paste, this is not gonna work with JS, you need to convert this into JS USE API syntax.

http://aempodcast.com/2015/javascript/understanding-javascript-use-api-aem/#.W3rfP2aB3q1

Answers (6)

Answers (6)

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K
smacdonald2008

20-08-2018

Here is another AEM 6.3 article that shows you how to work with HTL and JS USE API -- Creating a Tab layout component for Adobe Experience Manager

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K
smacdonald2008

20-08-2018

Are you using JS USE API to work with a HTL component?

Avatar

Avatar

karlw37000147

Avatar

karlw37000147

karlw37000147

20-08-2018

that doesnt work if i just copy and past that into my javascript. is there something else i need to do to get the java working in javascript?

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

3.0K

Likes

1.1K

Correct Reply

840

Avatar

Arun_Patidar

MVP

Total Posts

3.0K

Likes

1.1K

Correct Reply

840
Arun_Patidar
MVP

20-08-2018

You can loop through to get desire property like

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
}

No JS USE API is a way to write java inside JS, so won't be a problem.

Avatar

Avatar

karlw37000147

Avatar

karlw37000147

karlw37000147

20-08-2018

i cant use that because i wont always know the names of the nodes.

i am using javascript by the way so would this cause any problems?

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

3.0K

Likes

1.1K

Correct Reply

840

Avatar

Arun_Patidar

MVP

Total Posts

3.0K

Likes

1.1K

Correct Reply

840
Arun_Patidar
MVP

20-08-2018

Hi,

getItem() returns ValueMap, you can read values from value map like

  dbUserName = valueMapObj.get("dbUser", "No UserId found");

 

ValueMap ("The Adobe AEM Quickstart and Web Application.")