Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
let stars = [];
    // Loop 5 times
    for (var i = 1; i <= 5; i++) {
      // set the path to filled stars
      let path = require('./star-filled.png');
      if (i > this.state.cRating) {
        path = require('./star-unfilled.png');
      }
      stars.push((<TouchableHighlight onPress={ _ => this._RateApp(i) }><Image style={styles.image} source={path} /></TouchableHighlight>));
    }


In
this._RateApp(i)
function, I am getting the value of i as 6 for all the images.Please explain.

What I have tried:

closures - dealing with loops in javascript, only last item gets affected? - Stack Overflow[^]
Posted
Updated 27-Nov-18 3:39am

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900