This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Feb 21, 2012, 9:50 PM
8 Posts
topic has been resolvedResolved

nested Repeats

  • Category: Server Side JavaScript
  • Platform: Not Applicable
  • Release: 8.5.2
  • Role: Developer
  • Tags: nested Repeats
  • Replies: 2
Hi,

I'd like to display my data in a similar way as they are displayed in categorized views. I'm planning to do it using nested Repeats.
The data collection is in a JSON object, and the 'category' member of the JSON object would become the 'category', the other 2 members would be displayed under the corresponding categories.

myJSONObject = [
{'category' : 'a', 'product' : '1', 'price': '100'},
{'category' : 'a', 'product' : '2', 'price': '101'},
{'category' : 'a', 'product' : '3', 'price': '102'},
{'category' : 'b', 'product' : '11', 'price': '110'},
{'category' : 'b', 'product' : '12', 'price': '111'},
{'category' : 'c', 'product' : '24', 'price': '123'},
{'category' : 'c', 'product' : '25', 'price': '124'},
{'category' : 'c', 'product' : '26', 'price': '125'}]

I created an outer and an inner Repeat. For the outer Repeat I derived a unique array from the 'category' member of the JSON object, while for the inner Repeat I bound the JSON object. The Collection Name  for the inner Repeat is 'coll' and the value for the computed field within the Repeat is 'coll.product'.
The problem is that the inner Repeat displays all elements of the JSON object regardless of category, instead of showing only data that falls under the corresponding category. So it looks something like this:

a
   1
   2
   3
   11
   12
   24
   25
   26

b
   1
   2
   3
   11
   12
   24
   25
   26

c
   1
   2
   3
   11
   12
   24
   25
   26

How could this issue be resolved?
Thank you,

Etyien
Feb 22, 2012, 10:42 AM
261 Posts
Re: nested Repeats
For the inner repeat, you need to limit the objects that are displayed based on the outer category.
 
Let's assume that "category" is the collection name for the category in the outer repeat, to limit the collection of the inner repeat you could do something like:
 
var innerColl = [];
 
for (var i=0; j=myJSONObject.length, i<j; i++) {
 if (myJSONObject[i].category.equals( category )) {
  innerColl .push( myJSONObject[i] );
 } 
}
 
return innerColl ;
 
Mark
Feb 22, 2012, 11:06 AM
8 Posts
Re: nested Repeats
Thanks very much Mark, it works like a charm!
 
Etyien

This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal