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

这样就没问题了

相关推荐
WordPress学习笔记13 分钟前
解决Bootstrap下拉菜单一级链接无法点击的问题
前端·bootstrap·html
Never_Satisfied21 分钟前
C#插值字符串中大括号表示方法
前端·c#
踢球的打工仔1 小时前
typescript-类
前端·javascript·typescript
天天打码1 小时前
Svelte-无虚拟DOM、极致性能的现代高性能Web开发框架!
前端·node.js·vue·svelte
0思必得01 小时前
[Web自动化] Selenium元素定位
前端·python·selenium·自动化·html
EEEzhenliang2 小时前
CSS知识概括、总结
前端·css
大阳光男孩2 小时前
ElementUI表格懒加载子级更新数据刷新不生效问题
前端·javascript·elementui
wy3136228212 小时前
C#——意框架(结构说明)
前端·javascript·c#
研☆香2 小时前
JS中的三种显示弹窗
开发语言·前端·javascript
俩毛豆2 小时前
HarmonyOS APP开发-一文讲清使用Web组件加载网页的三种方法-《精通HarmonyOS NEXT :鸿蒙App开发入门与项目化实战》读者福利
前端·华为·harmonyos