M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

Looping list item using jquery or javascript

hi,

How do I loop a list component items using javascript or jquery?

Thanks

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Looping list item using jquery or javascript

Hello!

Please try the following
prevar listitems = $("[name=YOUR_LIST_GOES_HERE_NAME]");/pre

M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

Looping list item using jquery or javascript

That gives me a reference to the list component. And then to loop I tried this

code
var listitems = $("[name=YOUR_LIST_GOES_HERE_NAME]");
listitems.each(function() {
console.log($(this).text());
});
/code

I know I am missing something small here

M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

Looping list item using jquery or javascript

OK thanks I got it

Christian7378311
Posts: 0
Joined: Thu Feb 12, 2015 12:26 pm

Looping list item using jquery or javascript

Hi guys

This seems good, but how would you write the JS to loop through each item and ex. get each item "name" property from the individual list items?

Or let's say I wanted to change the "visible" property on all list items, which has class=allowed ?

Thanks!

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Looping list item using jquery or javascript

Hello Christian!

Sorry, but writing custom JS is outside the scope of support.

We may try to help if you clarify what have you tried and what exactly doesn't work?

Christian7378311
Posts: 0
Joined: Thu Feb 12, 2015 12:26 pm

Looping list item using jquery or javascript

No worries. I figured it out with help from another answer from this forum.

For future reference (for other developers), here's how I made it work for me:

This JS runs as Success Event from a DB service:

Code: Select all

 if (data === null || data.length === 0) 
 { 
     alert("No data received"); 
 } 
 else { 
     $.each(this.response.body, function(index, val) { 

         var listitems = $("[name=productListItem]"); 

         $.each(listitems, function(index, value) { 

             if ($(this).find("[name=productID]").html() == val.product_id) { 
                 $(this).show(); 
             } 
         }); 
     }); 
 }
Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Looping list item using jquery or javascript

Thanks for posting that!

Return to “Issues”