Calculating JavaScript rows and columns for PDF

0

I need to understand this js code snippet which is responsible for calculating the positioning of rows and columns, from a table html, to PDF.

$(el).find('tbody').find('tr').each(function(index,data) {
      rowCalc = index+1;                                            
      if (rowCalc % 35 == 0){
            doc.addPage();
            page++;
            startRowPosition=startRowPosition+10;

      }
      rowPosition=(startRowPosition + (rowCalc * 10)) - ((page -1) * 280);

      $(this).filter(':visible').find('td').each(function(index,data) {
            if ($(this).css('display') != 'none'){  
                if(defaults.ignoreColumn.indexOf(index) == -1){
                        var colPosition = startColPosition+ (index * 50);                                   
                        doc.text(colPosition,rowPosition, parseString($(this)));
                }
            }
    }); 
}); 

The biggest puzzle is in:

  

function (index, data)

I can not understand what this function represents and what and what are the values of the index and date parameters.

    
asked by anonymous 25.09.2018 / 21:49

1 answer

0

Hello, how are you?

So that part of the code in particular represents the initialization of a forEach of Jquery.

each(function(index,data) {}

That is, each element of the $(this).filter(':visible').find('td') array will be iterated by for each, the index parameter refers to a counter of the element being iterated. The date is the value being iterated.

Example:

const test = ['a','b','c']
$test.each(function(index, data){
  console.log(index, data) //vai printar na primeira iteracao (0, a)
  console.log(index, data) //vai printar na segunda iteracao (1, b)
  console.log(index, data) //vai printar na terceira iteracao (2, c)
}

Here is the Jquery documentation link with more examples of using $ each : link

    
26.09.2018 / 03:50