Reputation: 4705
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?
Upvotes: 0
Views: 2895
Reputation: 608
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.
Upvotes: 0
Reputation: 4705
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;
Upvotes: 0
Reputation: 66
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
Upvotes: 1