javascript - 如何在 JSX 中循环尝试数据

标签 javascript reactjs ecmascript-6 jsx

您好,我想在 UI 中显示这些数据。 我希望能够循环尝试数据并在 li 中显示 ProductTypeID 和 ProductTypeName

我希望能够在 jsx 中循环

我实在是想不通,你们能给我一点提示吗?我不太擅长处理数据和循环它。

[{
  "ProductTypeID": 14,
  "ProductTypeName": "ItemName1",
  "ProductTypeImageUrl": "",
  "ProductTypeThumbUrl": "",
  "ProductTypeIconUrl": "",
  "IsActive": 1,
  "ProductTypeBlueImage": null,
  "Is3HourRent": null
}, {
  "ProductTypeID": 1,
  "ProductTypeName": ItemName2",
  "ProductTypeImageUrl": "",
  "ProductTypeThumbUrl": "",
  "ProductTypeIconUrl": "",
  "IsActive": 1,
  "ProductTypeBlueImage": null,
  "Is3HourRent": false
}, {
  "ProductTypeID": 10,
  "ProductTypeName": "ItemName3",
  "ProductTypeImageUrl": "",
  "ProductTypeThumbUrl": "",
  "ProductTypeIconUrl": "",
  "IsActive": 1,
  "ProductTypeBlueImage": null,
  "Is3HourRent": true
}]

最佳答案

render() {
 var data = [{
  'ProductTypeID': 14,
  'ProductTypeName': 'ItemName1'
 }, 
 {
  'ProductTypeID': 15,
  'ProductTypeName': 'ItemName2'
 }];

 return (<ul>
  {data.map((item) => {
   return (<li key={item.ProductTypeID}>
     <span>ID: {item.ProductTypeID}</span>
     <span>Name: {item.ProductTypeName}</span>
   </li>);
  })}
 </ul>);
}

关于javascript - 如何在 JSX 中循环尝试数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39207856/

相关文章:

javascript - 切换嵌套列表中的链接不可单击

javascript - 在调整浏览器窗口大小时防止 jQuery 弹出窗口换行

reactjs - 'MouseEvent<Element, MouseEvent>' 类型不可分配给 'MouseEvent<HTMLDivElement, MouseEvent>' 类型

css - 无法在 react 中导入css文件

javascript - 是否可以重新初始化默认的 firebase 应用程序?

reactjs - 立即导出 ES6(React、Webpack、Babel)

javascript循环嵌套数组并根据另一个数组提取属性

javascript - JS 时间跟踪器未按预期工作

javascript - 如何在 node.js 中通过 XPath 更改带有 xmldom 的 DOM?

javascript - const {name, value} = event.target -- 这是什么意思