Hi,

On 06.08.2010 01:47, Tony Giaccone wrote:
> 
> 
> 
> So I'm trying to get the data in the lineItems. 
> 
> Here's the XML fragment
> 
> <lineItems jcr:primaryType="sling:OrderedFolder" 
> jcr:created="2010-08-02T19:54:57.329-04:00" jcr:createdBy="admin">
>       <_x0031_ jcr:primaryType="nt:unstructured" lineItemSeq="1" itemId="55"  
> itemDescr="Item selected to purchase" 
> sling:resourceType="mll/item"></lineItems>
> 
> 
> I tried this:
> 
> 
>                               <% var items = currentNode.lineItems; %>
>                               <% for (var i = 0;i<items.length;i++) %>

This is the problem.

The items variable is a JavaScript wrapper for the Node interface. As
such it is not an array and does not have a length property.

If you want to iterate over the child nodes of items, the best thing is
to call the getNodes() method like this:

    <%
    var items = currentNode.lineItems.getNodes();
    for (var i=0; i < items.length; i++) {
        %><%= items[i].itemDescr %><%
    }
    %>

The items object here is actually a normal Object where the contained
nodes can also be accessed by name (unless as in your example, the node
names are numbers....).

Hope this helps.

Regards
Felix

>                               <% { %>
>                               <%= currentNode.lineItems[i].itemDescr %>
>                               <% } %>
>                               <b> End of loop</b><br/>
> 
> And get this message:
> 
> TypeError: Cannot read property "shortDescr" from undefined 
> 
> 
> 
> 
> 
> So I change it to this:
> 
>                               <% var items = currentNode.lineItems; %>
>                               <% for (var i = 0;i<items.length;i++) %>
>                               <% { %>
>                               <%= currentNode.lineItems[i] %>
>                               <% } %>
>                               <b> End of loop</b><br/>
> 
> This is what I get..
> undefined End of loop
> 
> Change the code to this:
> 
>                               <% var items = currentNode.lineItems; %>
>                               <% for (var i = 0;i<items.length;i++) %>
>                               <% { %>
>                               <%= currentNode.lineItems %>
>                               <% } %>
>                               <b> End of loop</b><br/>
> 
> And I get this:
> 
> content/Documents/2008/1155383/Order/2_1280793297315/lineItems
> End of loop
> 
> I'm guessing I need to do something to load that node(?) into the page? 
> 
> 
> Tony

Reply via email to