Grid with labels, loop to get the values

This forum contains topics that were moved from Get Satisfaction
Takis
Posts: 0
Joined: Wed Oct 22, 2014 5:10 pm

Grid with labels, loop to get the values

Post by Takis »

Hi team

I have a grid which contains only labels.
I get the values of the labels from a DB service, which work fine.
One of the labels in the grid contains an address.
But as many records returned from DB, I get of course many address labels.
The label in the grid that holds the address is called ResultText5.

I want, after the records are returned from DB and displayed in the page, to loop inside the grid, get the values of only the labels with name ResultText5, separate them with "," and save them in a local variable.

How in general can we loop on the objects inside a grid and get values?

Thanks!

Takis
Posts: 0
Joined: Wed Oct 22, 2014 5:10 pm

Grid with labels, loop to get the values

Post by Takis »

Help!

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

Grid with labels, loop to get the values

Post by Maryna Brodina »

Hello!

Try the following way:

pre// get all values
var values = $('[name="ResultText5"]').map(function(index,element){
return $(element).text();
}).get().join(',');
// save the values
localStorage.setItem('values', values);/pre

Takis
Posts: 0
Joined: Wed Oct 22, 2014 5:10 pm

Grid with labels, loop to get the values

Post by Takis »

I love you!
Works thanks.

A general suggestion, if I may.
It would be good to be in documented examples how to do this with dynamically build grids that contains labels, buttons, checkboxes, etc, as I see many people use this approach.
I mean how to get or set properties of objects in such cases.
If documentation already exists, please give a link.

Thanks again!

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

Grid with labels, loop to get the values

Post by Maryna Brodina »

:) Added your request to the doc requests update list. Hope we can add such examples.

Takis
Posts: 0
Joined: Wed Oct 22, 2014 5:10 pm

Grid with labels, loop to get the values

Post by Takis »

Hi

Suppose that I have a grid with 6 labels "Lable1"..."Lable6" , with text populated by DB service

Can I loop from all labels in a record and store its values in a multi dimension array? Like an expansion of the above code you gave me.

For exampe:
record1= array[1]
record2=array[2]

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Grid with labels, loop to get the values

Post by Yurii Orishchuk »

Hi Panagiotis,

Yes you can do it.

this is code example:

pre

var resultArray = [];

//Where "itemName" is your item component name.
var items = jQuery('[name="itemName"]');

var labels = {
attr1: "label1",
attr2: "label2",
attr3: "label3",
attr4: "label4",
attr5: "label5"
};

for(var i = 0; i < items&#46;length; i++){
var item = jQuery(items);

Code: Select all

 resultArray[i] = []; 

 for(var j = 0; j < labels&#46;length; j++){ 
    resultArray[i][j] = item&#46;find('[name="' + labels[i] + '"]')&#46;text(); 
 }; 

};

console&#46;log(resultArray);

/pre

Regards.

Takis
Posts: 0
Joined: Wed Oct 22, 2014 5:10 pm

Grid with labels, loop to get the values

Post by Takis »

In one page, I am trying to get all the checkboxes that I created dynamically, that are checked and get its values.

I got up to this point of code

code
var items = jQuery('[name="mobilecheckbox_157"]');
alert ( "how many chbx:" + jQuery('[name="mobilecheckbox_157"]')&#46;length );
for (var i = 0; i < items&#46;length; i++){
var item = jQuery(items);
alert ( item&#46;text()&#46;trim() );

}
/code

I want to get only the checked and store its name in an array.

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Grid with labels, loop to get the values

Post by Yurii Orishchuk »

Hi Panagiotis:

You need to add ":checked" selector to your jQuery search.

Details: http://api.jquery.com/checked-selector/

pre

var items = jQuery('[name="mobilecheckbox_336"] input:checked');

alert("how many chbx:" + items&#46;length);
for (var i = 0; i < items&#46;length; i++) {
var item = jQuery(items)&#46;closest('[name="mobilecheckbox_336"]');

Code: Select all

 alert(item&#46;text()&#46;trim()); 

}

/pre

Regards.

Post Reply