将一个元素数组渲染进 DOM

index.js

import React, { Component } from ‘react‘
import ReactDOM from ‘react-dom‘

class Bar extends Component {
  constructor() {
    super()
    this.state = {
      list: [‘Lilei‘, ‘Hanmeimei‘, ‘Lihua‘],
    }
  }
  clickHandler = value => {
    alert(value)
  }
  render() {
    const btns = this.state.list.map((item, index) => {
      return (
        <button key={index} onClick={this.clickHandler.bind(this, item)}>
          {item}
        </button>
      )
    })
    return <div>{btns}</div>
  }
}

ReactDOM.render(<Bar />, document.getElementById(‘root‘))

将一个元素数组渲染进 DOM

上一篇:Linux磁盘管理


下一篇:UVa 11992