You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Radu Cotescu (JIRA)" <ji...@apache.org> on 2017/08/31 08:27:00 UTC
[jira] [Comment Edited] (SLING-6085) resource.getValueMap() to
unavailable in Sightly JS-code
[ https://issues.apache.org/jira/browse/SLING-6085?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16148637#comment-16148637 ]
Radu Cotescu edited comment on SLING-6085 at 8/31/17 8:26 AM:
--------------------------------------------------------------
You actually can write this:
{code:javascript}
use(function () {
'use strict';
var parent = resource.parent;
var parentProperties = parent.properties;
return parentProperties['jcr:createdBy']; // equivalent to parentProperties.get('jcr:createdBy')
});
{code}
It's way cleaner and more JavaScript-like than {{resource.getValueMap()}}.
was (Author: radu.cotescu):
You actually can write this:
{code:javascript}
use(function () {
'use strict';
var parent = resource.parent;
var parentProperties = parent.properties;
return parentProperties['jcr:createdBy']; // equivalent to parentProperties.get('jcr:createdBy')
});
{code}
It's way cleaner and more JavaScript like than {{resource.getValueMap()}}.
> resource.getValueMap() to unavailable in Sightly JS-code
> --------------------------------------------------------
>
> Key: SLING-6085
> URL: https://issues.apache.org/jira/browse/SLING-6085
> Project: Sling
> Issue Type: Bug
> Components: Scripting
> Affects Versions: Scripting JavaScript 2.0.2
> Reporter: Feike Visser
> Assignee: Radu Cotescu
>
> In Sightly JS-api you can't use resource.getValueMap() method, looks like it is unavailable.
> There you need to do this workaround to get to the properties
> {code}
> "use strict";
> use(function () {
> var parent = resource.getParent();
> var props = parent.adaptTo(Packages.org.apache.sling.api.resource.ValueMap);
> return props.get("jcr:createdBy","");
> });
> {code}
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)