Monday, 11 September 2017

javascript - For loop in react render method




I want create paging link for my grid.I pass maxPages(number) property to component but i cant use for in render method. What can i do ?



var Pagination = React.createClass({

render: function(){


return(




  • «

  • {for (var i=0;i <10;i++;)
    {
    return(
  • i + 1
  • );
    }
    }

  • »



);

}});

Answer



You can run the loop before the rendering (note that there's an error in your for loop)



var lis = [];


for (var i=0; i<10; i++) {
lis.push(
  • {i + 1}
  • );
    }

    var Pagination = React.createClass({
    render: function(){
    return(



    );
    }
    });



    FIDDLE


    No comments:

    Post a Comment

    casting - Why wasn&#39;t Tobey Maguire in The Amazing Spider-Man? - Movies &amp; TV

    In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...