【问题标题】:How can render a reactJs in a nested Object Array?如何在嵌套对象数组中渲染 reactJs?
【发布时间】:2021-12-27 16:54:47
【问题描述】:

如何获取数组中的 tchStudents 并在 reactJS 中渲染?

 const {
      tchFirstName, 
      tchLastName, 
      tchStudents
 } = teacher; 

 <tbody>
    <tr>
      <td>{tchID}</td>
      <td>{tchFirstName}</td>
      <td>{tchLastName}</td>
      <td>{tchStudents.stdID} // ←←← this is Schema.Types.ObjectId 
    </td>

 Object.keys(tchStudents).map((key) => (tchStudents[key].map((item) =>
    <p> {item.stdID} </p> 
    )
 ))
 

错误:对象作为 React 子对象无效(发现:对象具有键 {_id、stdStatus、stdID、stdFirstName、stdLastName、stdGender、__v})。如果您打算渲染一组子项,请改用数组。

谢谢你帮助我!!!

【问题讨论】:

    标签: node.js reactjs mongoose


    【解决方案1】:
    data.docs.map(x => x.tchStudentsCopy)
    

    然后,如果您想使用 tchStudentsCopy 数组中的任何内容,请执行另一个映射以提取您想要的内容。

    【讨论】:

    • 等待 amila 我先编辑
    猜你喜欢
    • 2017-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-06
    • 1970-01-01
    • 2020-06-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多