You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Eric Norman (JIRA)" <ji...@apache.org> on 2008/06/14 02:41:45 UTC
[jira] Commented: (SLING-291) Clarify and test access to
multi-valued Properties from server-side javascript
[ https://issues.apache.org/jira/browse/SLING-291?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12605020#action_12605020 ]
Eric Norman commented on SLING-291:
-----------------------------------
I'm my opinion this is indeed a bug. Multi-valued properties should always be an array in the script, even if it contains only a single value. Otherwise the developer must write extra code to handle single vs. multi-valued properties.
For example:
<%
var prop = currentNode["prop1"];
if (!(prop instanceof Array)) {
//handle single-val here
} else {
//handle mult-val here
for (i=0; i < prop.length;i++)
var data = prop[i];
//do something with data
}
}
%>
> Clarify and test access to multi-valued Properties from server-side javascript
> ------------------------------------------------------------------------------
>
> Key: SLING-291
> URL: https://issues.apache.org/jira/browse/SLING-291
> Project: Sling
> Issue Type: Improvement
> Components: Scripting
> Reporter: Bertrand Delacretaz
> Priority: Minor
>
> In SLING-282, Michael Marth writes:
> the property "to" is multivalued.
> in the script I do something like:
> <%= currentNode["to"][0] %>
> if the value of "to" has only one value I seem to get back this value as one string so [0] gives me the first character. if "to" has 2 values I get back a collection so [0] gives me the first element. this is consistent with what ["to"].length gives me.
> I am not 100% sure if this is a bug (might be my lack of understanding for javascript), if so a comment on how to determine the result length of a multi-valued property would be appreciated.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.