React equivalent for ng-repeat

后端 未结 5 1128
梦谈多话
梦谈多话 2021-02-06 21:43

I am new to React.js. I am trying to bind data arrays. I am looking for the equivalent of ng-repeat, but i can\'t find it inside documentation.

e.g:

var         


        
5条回答
  •  情歌与酒
    2021-02-06 22:32

    To perform the same task as ng-repeat in React you just need to think natively. Under the hood ng-repeat is just using a native Javascript iterator. You can use the same sort of native iterator directly in React. For example, I`ll use Array.map:

    var RepeatModule = React.createClass({
      getInitialState: function() {
        return { items: [] } 
      }, 
      render: function() {
    
        var listItems = this.props.items.map(function(item) {
          return (
            
  • {item.name}
  • ); }); return (
      {listItems}
    ); } });

    I got the above example from http://angulartoreact.com/ng-repeat-react-equivalent . The site has more examples of React equivaents to Angular directives.

提交回复
热议问题