Implementation of react loop data (list)

Implementation of react loop data (list)

First, let's simulate the data coming from the background. Here, in order to make the code clear, the data is simply simulated.

   import bg3 from './image/bg3.png'
   constructor(props){
      super(props)
      this.state = {
      ///Here list:[
            { id:1,img:bg3},
            { id:2,img:bg3},
            { id:3,img:bg3},
            { id:4,img:bg3},
            { id:5,img:bg3},
         ], 
     ///     
      }
   }

Then use the map method to loop out

  {
        this.state.list.map((item,key) => {
            return (
              <div className="winfor" onClick={() => console.log(item.id)}>
                 <img src={item.img} className="winforimg" />
                    
                 
              </div>
            )
          })
  }

Added: React loop list

import React, {Component} from 'react';
import logo from './logo.svg';
import './App.css';
import {Person,Twoway} from './Person/Person'
 
class App extends Component {
  state={
    persons:[{name:'Little Fairy',age:'18'},{name:'Xiaoyu',age:'18'},{name:'Jiaxuan',age:'18'}],
 
  }
 
  render(){
    const listItems = this.state.persons.map((item,index) =>
       <Person name={item.name} age={item.age} key={index} />
     );
      return(
        <div className="App">
             {listItems}
        </div>
      )      
  } 
} 
export default App;

This is the end of this article about the implementation of react loop data. For more relevant react loop data content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • React Native avatar scrolling example
  • React example of digital scrolling effect without plugins
  • React implements infinite loop scrolling information

<<:  How to use commands in Mysql to achieve hierarchical search help detailed explanation

>>:  Detailed installation and configuration of hadoop2.7.2 under ubuntu15.10

Recommend

JavaScript canvas implements moving the ball following the mouse

This article example shares the specific code of ...

js to realize a simple advertising window

This article shares the specific code of js to im...

idea uses docker plug-in to achieve one-click automated deployment

Table of contents environment: 1. Docker enables ...

Implementation of Docker deployment of Django+Mysql+Redis+Gunicorn+Nginx

I. Introduction Docker technology is very popular...

MySQL 8.0.21 installation tutorial with pictures and text

1. Download the download link Click download. You...

JavaScript data flattening detailed explanation

Table of contents What is Flattening recursion to...

Detailed explanation of CSS3 Flex elastic layout example code

1. Basic Concepts //Any container can be specifie...

Detailed explanation of the use of MySQL concatenation function CONCAT

The previous articles introduced the replacement ...

Docker meets Intellij IDEA, Java development improves productivity tenfold

Table of contents 1. Preparation before developme...

Linux five-step build kernel tree

Table of contents 0. The kernel tree that comes w...

Specific use of routing guards in Vue

Table of contents 1. Global Guard 1.1 Global fron...

An audio-visual Linux distribution that appeals to audiophiles

I recently stumbled upon the Audiovisual Linux Pr...

How to use Nginx to handle cross-domain Vue development environment

1. Demand The local test domain name is the same ...

Implementation of textarea adaptive height solution in Vue

Table of contents Hidden Problems Solution to ada...

Manual and scheduled backup steps for MySQL database

Table of contents Manual backup Timer backup Manu...