React equivalent for ng-repeat

后端 未结 5 1130
梦谈多话
梦谈多话 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:27

    Here is an example using ES6, and a stateless component.

    The below code demonstrates creating a menu by looping through a list of menu items.

    import React from 'react';
    import Menu from 'material-ui/lib/menus/menu';
    import MenuItem from 'material-ui/lib/menus/menu-item';
    
    
    const menuItems = [
        {route: '/questions', text: 'Questions'},
        {route: '/jobs', text: 'Jobs'},
        {route: '/tags', text: 'Tags'},
        {route: '/users', text: 'Users'},
        {route: '/badges', text: 'Badges'}
        {route: '/questions/new', text: 'Ask Question'}
    
    ].map((item, index) => );
    
    
    const Sidebar = ({history}) => (
         history.push(child.props.value)}
        >
            {menuItems}
        
    );
    
    
    export default Sidebar;
    

    Basically what we're doing is just pure javascript iteration utilizing Array.map.

提交回复
热议问题