【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)}

这样就没问题了

相关推荐
LJianK17 分钟前
BUG: Uncaught Error: [DecimalError] Invalid argument: .0
前端
No Silver Bullet17 分钟前
Nginx 内存不足对Web 应用的影响分析
运维·前端·nginx
一起养小猫21 分钟前
Flutter for OpenHarmony 实战 表单处理与验证完整指南
android·开发语言·前端·javascript·flutter·harmonyos
weixin_3954489127 分钟前
main.c_cursor_0130
前端·网络·算法
C澒43 分钟前
SGW 接入层运维实战:配置查看 + 监控分析 + 日志排查
前端·安全·运维开发
德育处主任Pro1 小时前
『NAS』在群晖部署一款太空策略游戏-ogame-vue-ts
前端·vue.js·游戏
ziqi5222 小时前
第二十五天笔记
前端·chrome·笔记
GISer_Jing2 小时前
Memory、Rules、Skills、MCP如何重塑AI编程
前端·人工智能·aigc·ai编程
xcs194052 小时前
前端 项目构建问题 \node_modules\loader-runner\lib\loadLoader.js
开发语言·前端·javascript
广然2 小时前
EVE-NG 镜像管理工具 1.1 Web 版本正式发布!
运维·服务器·前端