How to pass the counter " i " of the cycle for a function parameter?

Asked

Viewed 20 times

0

Hello I am trying to implement a dynamic table with React Native, and the table data should be dynamic, so far so good. But the records of one of the columns must be a button that calls a function.

function _renderRegional(data) {

    if(data == 'channel') {
        var row = [];

        for(var i = 0; i < count; i++) { 
            row[i] = <Row><TouchableOpacity onPress={() => buscaLojas(`dados[${i}].code`)}><Text>Regional {dados[0].Regional}</Text></TouchableOpacity></Row>
        }

        return(
            row
        );
    }
}

And here the table:

<View>
     <Grid>
          <Col>
              <Row><TextReact>Regional</TextReact></Row>
              {_renderRegional('channel')}
          </Col>
     </Grid>
</View>

Renders all right, but the value of the parameter that case is " i " is always one last counter value for all lines.

  • See the linked question at the top. Basically, replace var for let within the for.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.