Page 1 of 1

Looping list item using jquery or javascript

Posted: Thu Feb 05, 2015 12:20 pm
by M&M

hi,

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

Thanks


Looping list item using jquery or javascript

Posted: Thu Feb 05, 2015 12:38 pm
by Evgene Karachevtsev

Hello!

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


Looping list item using jquery or javascript

Posted: Thu Feb 05, 2015 2:03 pm
by M&M

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


Looping list item using jquery or javascript

Posted: Thu Feb 05, 2015 2:07 pm
by M&M

OK thanks I got it


Looping list item using jquery or javascript

Posted: Thu Feb 12, 2015 12:26 pm
by Christian7378311

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!


Looping list item using jquery or javascript

Posted: Thu Feb 12, 2015 1:13 pm
by Maryna Brodina

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?


Looping list item using jquery or javascript

Posted: Thu Feb 12, 2015 2:20 pm
by Christian7378311

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(); 
             } 
         }); 
     }); 
 }

Looping list item using jquery or javascript

Posted: Thu Feb 12, 2015 2:29 pm
by Maryna Brodina

Thanks for posting that!