反应表不显示的单元数据

发布于 2025-02-08 00:32:07 字数 2699 浏览 3 评论 0 原文

我的数据在反应表的单元格内不可见:

import React, { useMemo } from 'react'
import { useTable } from 'react-table/dist/react-table.development'
import MOCK_DATA from '../mock/components/LandingTableMock.json'
import { COLUMNS } from './LandingTableColumns'
import '../static/styles/globalVar.css'

export const LandingTable = () => {
  
    const columns = useMemo(() => COLUMNS, [])
    const data = useMemo(() => MOCK_DATA, [])
    

    const tableInstance = useTable ({
        columns: columns, //columns: COLUMNS,
        data //data: MOCK_DATA
    })

    const { 
        getTableProps, 
        getTableBodyProps, 
        headerGroups, 
        rows, 
        prepareRow 
    } = tableInstance

    return (
        
        <table {...getTableProps()}>
            <thead>
                {
                    headerGroups.map((headerGroup) =>  (
                    <tr {...headerGroup.getHeaderGroupProps()}>
                        {
                            headerGroup.headers.map((column) => (
                                <th {...column.getHeaderProps()}> 
                                    {column.render('Header')}
                                </th>
                            )
                        )}
                    </tr>
                    ))
                }
            </thead>
            <tbody {...getTableBodyProps()}>
                {rows.map((row) => {
                    prepareRow(row)
                    return (
                        <tr {...row.getRowProps()}>
                            {row.cells.map( (cell) => {
                                return <td {...cell.getCellProps()}> {cell.render('Cell')}</td>
                            })}
                        </tr>
                    )
                })}
            </tbody>
        </table>
    )
}

我放了一个断点以检查单元格的价值并且不确定。

MOCK_DATA和列看起来不错,这不是包括问题。我将它们移到同一文件中,但仍然无法使用。

结果是一个表格,有一个正确的行数但空单元格:

< img src =“ https://i.sstatic.net/1qezj.png” alt =“在此处输入图像说明”>

我关注教程。

My data is not visible inside the react-table's cells:

import React, { useMemo } from 'react'
import { useTable } from 'react-table/dist/react-table.development'
import MOCK_DATA from '../mock/components/LandingTableMock.json'
import { COLUMNS } from './LandingTableColumns'
import '../static/styles/globalVar.css'

export const LandingTable = () => {
  
    const columns = useMemo(() => COLUMNS, [])
    const data = useMemo(() => MOCK_DATA, [])
    

    const tableInstance = useTable ({
        columns: columns, //columns: COLUMNS,
        data //data: MOCK_DATA
    })

    const { 
        getTableProps, 
        getTableBodyProps, 
        headerGroups, 
        rows, 
        prepareRow 
    } = tableInstance

    return (
        
        <table {...getTableProps()}>
            <thead>
                {
                    headerGroups.map((headerGroup) =>  (
                    <tr {...headerGroup.getHeaderGroupProps()}>
                        {
                            headerGroup.headers.map((column) => (
                                <th {...column.getHeaderProps()}> 
                                    {column.render('Header')}
                                </th>
                            )
                        )}
                    </tr>
                    ))
                }
            </thead>
            <tbody {...getTableBodyProps()}>
                {rows.map((row) => {
                    prepareRow(row)
                    return (
                        <tr {...row.getRowProps()}>
                            {row.cells.map( (cell) => {
                                return <td {...cell.getCellProps()}> {cell.render('Cell')}</td>
                            })}
                        </tr>
                    )
                })}
            </tbody>
        </table>
    )
}

I put a breakpoint to inspect the cells value and is undefined.
enter image description here

MOCK_DATA and COLUMNS are looking fine, it`s not an include problem. I moved them in the same file and it still does not work.

enter image description here

The result is a table with the right number of rows but empty cells:

enter image description here

I followed this tutorial on youtube.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文