AEM (cq5) Working with information within a component

旧巷老猫 提交于 2019-12-25 02:56:06

问题


I have a component in which I am able to get some basic information about its parent resource.

var parent = granite.resource.getParent();

I am now trying to get the property "path" (parent.path) within the JavaScript that accompanies my component however the data is not available inside the script but within the HTML that renders the component the property "path" is available.

Could some one shine some light on why it is possible within the HTML but not the JavaScript?


回答1:


You should be able to do this with currentNode.getParent().getPath(); (I have tested this on the geometrixx-outdoors/en/activities/cajamara-biking.html page)

As you mentioned, you have access to a lot of default objects, mentioned here: http://docs.adobe.com/docs/en/aem/6-0/develop/sightly/global-objects.html.

These are simply Java backed objects (the full class name is in the Description field). To find out more information, Google the class name. For example, the currentNode is a javax.jcr.Node class, and the methods available on it are documented here: http://www.day.com/specs/jsr170/javadocs/jcr-2.0/javax/jcr/Node.html




回答2:


In order to get the path I had to use "currentNode.getParent().path" per @Bambara's instructions.

var parent = currentNode.getParent();
var path = parent.path;



回答3:


I think that currentNode.getParent().getPath() return a Java String object which may not work properly in JavaScript if you do a var path = ""+ currentNode.getParent().getPath(); will put path in a Javascript string, don't forget Rhino is the middleman between your Java objects and Javascript script, so any Java object which is a Bean can be accessed using .path instead of getPath() because Rhino will do the conversion. So the Getters and Setters will be automatically called when you read .path or set .path = "/some/path" if there is a setter for this property of course.

With JS server side you have access to the whole Java objects just make sure you convert to the right primitive so your data is usable.



来源:https://stackoverflow.com/questions/29476918/aem-cq5-working-with-information-within-a-component

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!