logo
  • 教程列表
  • SO官方文档
  • React 中的键
    • 使用元素的 id
    • 使用数组索引
  1. StackOverflow 文档
  2. React 教程
  3. React 中的键
  4. 使用数组索引

使用数组索引

Created: November-22, 2018

如果你手头没有唯一的数据库 ID,你还可以使用数组的数字索引,如下所示:

render() {
  const { todos } = this.props;
  return (
    <ul>
      { todos.map((todo, index) =>
        <li key={ `todo-${index}` }>
          { todo.text }
        </li>
      }
    </ul>
  );
}
  • 使用元素的 id

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 关于我们
  • 免责声明