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

  • 關於本站
  • 免責聲明