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

这样就没问题了

相关推荐
一只小bit1 天前
Qt 文件:QFile 文件读写与管理教程
前端·c++·qt·gui
午安~婉1 天前
整理知识点
前端·javascript·vue
军军君011 天前
Three.js基础功能学习十二:常量与核心
前端·javascript·学习·3d·threejs·three·三维
m0_748254661 天前
CSS AI 编程
前端·css·人工智能
27669582921 天前
dy bd-ticket-guard-client-data bd-ticket-guard-ree-public-key 逆向
前端·javascript·python·abogus·bd-ticket·mstoken·ticket-guard
m0_726365831 天前
哈希分分预测系统 + Python Worker + Web 仪表盘”小系统(PHP + MySQL)
前端·python·哈希算法
WX-bisheyuange1 天前
基于SpringBoot的交通管理在线服务系统
前端·javascript·vue.js·毕业设计
Coder_Boy_1 天前
基于SpringAI的在线考试系统-考试系统DDD(领域驱动设计)实现步骤详解(2)
java·前端·数据库·人工智能·spring boot
GIS之路1 天前
ArcGIS Pro 实现影像波段合成
前端·python·信息可视化
m0_748254661 天前
CSS id 和 classid 和 class 选择器
前端·css