码迷,mamicode.com
首页 > 其他好文 > 详细

React 函数传参

时间:2018-06-04 11:46:22      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:tag   items   end   and   word   err   code   div   from   

import React, { Component } from ‘react‘;
import { render } from ‘react-dom‘;

class GroceryList extends Component {
  handleClick(i) {
    console.log(‘You clicked: ‘ + this.props.items[i]);
  }

  render() {
    return (
      <div>
        {this.props.items.map((item, i) => {
          return (
            <div onClick={this.handleClick.bind(this, i)} key={i}>{item}</div>
          );
        })}
      </div>
    );
  }
}

render(
  <GroceryList items={[‘Apple‘, ‘Banana‘, ‘Cranberry‘]} />, mountNode
);

React 函数传参

标签:tag   items   end   and   word   err   code   div   from   

原文地址:https://www.cnblogs.com/winyh/p/9131620.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!