【Ant Design】【List】

源码

javascript 复制代码
   <List
       style={{
          width: 600,
          height: 200,
          overflow: 'auto',
        }}
        header={
          <>
            <Typography.Text
              copyable={{
                text: file.response.join(',') || '',
              }}
            />
          </>
        }
        split={false}
        dataSource={file.response}
        renderItem={(item: any, index: number) => (
          <List.Item>
            <Typography.Text type="danger">{item}</Typography.Text>
          </List.Item>
        )}
      />

报错

Uncaught TypeError: Cannot read properties of null (reading 'key')

分析

第一反应是每个字项遍历出了问题

加上key,改为

复制代码
 <List.Item key={`${item}-${index}`}>
        <Typography.Text type="danger">{item}</Typography.Text>
   </List.Item>

依然报错,那就是原始数据有null,不支持了

将数据注入List组件时,再用String包一层,防止存在null

复制代码
 dataSource={file.response.map(String)}

这样就没问题了

相关推荐
threelab11 分钟前
Three.js 抽象艺术着色器效果 | 三维可视化 / AI 提示词
前端·javascript·人工智能·3d·着色器
萌新小码农‍22 分钟前
Python的input函数
java·前端·python
2301_8035389527 分钟前
CSS复合属性实战技巧与交互设计应用
前端
nashane30 分钟前
HarmonyOS 6学习:Web组件内嵌H5视频全屏“复活”指南
前端·学习·harmonyos
BY组态30 分钟前
Ricon组态系统:新一代Web可视化组态平台
前端·物联网·iot·web组态·组态
i_am_a_div_日积月累_35 分钟前
3.contextBridge桥梁
前端·javascript·vue.js·electron
bug-100861 小时前
hooks,mixin,pinia,vuex
前端·vue.js
Shirley~~1 小时前
npm包发布与 dist-tag 管理指南
前端·npm·node.js
Csvn1 小时前
前端可视化入门:Canvas、SVG 与 D3.js 基础
前端·d3.js
bug-100862 小时前
vue2和vue3的路由变化
前端·vue.js