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

Mini Program to Implement Sieve Lottery

This article example shares the specific code of ...

javascript implements web version of pinball game

The web pinball game implemented using javeScript...

Implementation of building Kubernetes cluster with VirtualBox+Ubuntu16

Table of contents About Kubernetes Basic environm...

A brief talk about the diff algorithm in Vue

Table of contents Overview Virtual Dom principle ...

Detailed analysis of the difference between Ref and Reactive in Vue3.0

Table of contents Ref and Reactive Ref Reactive T...

Detailed explanation of several methods of JS array dimensionality reduction

Dimensionality reduction of two-dimensional array...

How to install Docker on Windows 10 Home Edition

I recently used Docker to upgrade a project. I ha...

Vue Element front-end application development table list display

1. List query interface effect Before introducing...

Detailed explanation of basic operation commands for Linux network settings

Table of contents View network configuration View...

WeChat applet implements the Record function

This article shares the specific code for the WeC...

JavaScript to achieve a simple message board case

Use Javascript to implement a message board examp...

Super detailed basic JavaScript syntax rules

Table of contents 01 JavaScript (abbreviated as: ...

Six inheritance methods in JS and their advantages and disadvantages

Table of contents Preface Prototype chain inherit...