我正在使用ReactJS,ANTD表作为框架,但是我可以将数据显示在表中

发布于 2025-02-09 09:54:23 字数 2969 浏览 1 评论 0原文

我正在使用ReactJS和ANTD进行框架,试图用保存在服务器中的数据制作表。我提出以下代码,结果根本不好。请支持我。

import React, { useEffect, useState } from 'react'
import { FaCode } from "react-icons/fa";
import axios from "axios";
import { Card, Button, Col, Row, Table } from 'antd';
import { SketchOutlined } from '@ant-design/icons';




function LandingPage() {
    
    const [Products, setProducts] = useState ([]);
    
    
    useEffect(()=> {
        
        axios.post('/api/product/products')
            .then(response => {
                if (response.data.success) {
                    
                    setProducts(response.data.productInfo)
                } else {
                    alert("상품을 가져오는데 실패하였습니다.")
                }
        })
        
    }, [])
    

            
            
            const data = Products.map ((product, index) => (
                [{
                    item: product.item,
                    grade: product.grade,
                    price: product.price,
                    box: product.box,
                    key: 'index'
                }] 
            ))
        
        
            const columns = [
                {
                    title: '품명',
                    dataIndex: 'item',
                    key:'key',
                    render: item =>{
                    return <a>{item}</a>
                    }
                },
                {
                    title: '등급',
                    dataIndex: 'grade',
                    key:'key'
                },
                {
                    title: '수량',
                    dataIndex: 'box',
                    key:'key'
                },
                {
                    title: '가격(원)',
                    dataIndex: 'price',
                    key:'key'
                }
            ]
        
        
        console.log('products', Products)
    
    
    return (
        <div style={{ width: '75%', margin: '3rem auto' }}>
            
            <div style={{ textAlign: 'center' }}>
                <h2> 재고자료 <SketchOutlined /></h2>
                <h3>재고 LIST</h3>
            </div>
            
            {/* Filter */}
            
            {/* Search */}
            
            
            {/* Table */}
            
        
            <Table
                columns={columns}
                dataSource={data}
                />

            
            <br />
            <br />
            <div style={{ display: 'flex', justifyContent: 'center' }}>
            
                <Button type="primary">See More</Button>
            </div>
            
        </div>
    )
}

export default LandingPage

在这里输入映像

我有上传页面,我将5个项目上传到了桌子中,但是有未显示数据。只有5行... 我该如何解决这个问题?

谢谢。

I am using reactJS and antd for framework, trying to make the table with my data saved in the server. I put the below code and the result is not good at all. Please, support me.

import React, { useEffect, useState } from 'react'
import { FaCode } from "react-icons/fa";
import axios from "axios";
import { Card, Button, Col, Row, Table } from 'antd';
import { SketchOutlined } from '@ant-design/icons';




function LandingPage() {
    
    const [Products, setProducts] = useState ([]);
    
    
    useEffect(()=> {
        
        axios.post('/api/product/products')
            .then(response => {
                if (response.data.success) {
                    
                    setProducts(response.data.productInfo)
                } else {
                    alert("상품을 가져오는데 실패하였습니다.")
                }
        })
        
    }, [])
    

            
            
            const data = Products.map ((product, index) => (
                [{
                    item: product.item,
                    grade: product.grade,
                    price: product.price,
                    box: product.box,
                    key: 'index'
                }] 
            ))
        
        
            const columns = [
                {
                    title: '품명',
                    dataIndex: 'item',
                    key:'key',
                    render: item =>{
                    return <a>{item}</a>
                    }
                },
                {
                    title: '등급',
                    dataIndex: 'grade',
                    key:'key'
                },
                {
                    title: '수량',
                    dataIndex: 'box',
                    key:'key'
                },
                {
                    title: '가격(원)',
                    dataIndex: 'price',
                    key:'key'
                }
            ]
        
        
        console.log('products', Products)
    
    
    return (
        <div style={{ width: '75%', margin: '3rem auto' }}>
            
            <div style={{ textAlign: 'center' }}>
                <h2> 재고자료 <SketchOutlined /></h2>
                <h3>재고 LIST</h3>
            </div>
            
            {/* Filter */}
            
            {/* Search */}
            
            
            {/* Table */}
            
        
            <Table
                columns={columns}
                dataSource={data}
                />

            
            <br />
            <br />
            <div style={{ display: 'flex', justifyContent: 'center' }}>
            
                <Button type="primary">See More</Button>
            </div>
            
        </div>
    )
}

export default LandingPage

enter image description here

I have upload page and I uploaded 5 items into the table, but there is no data shown. only 5 rows...
How can I solve this problem?

Thank you.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北风几吹夏 2025-02-16 09:54:23

尝试在MAP功能中删除[]

const data = Products.map ((product, index) => ({
     item: product.item,
     grade: product.grade,
     price: product.price,
     box: product.box,
     key: 'index'
}))

Try to remove [] in your map function

const data = Products.map ((product, index) => ({
     item: product.item,
     grade: product.grade,
     price: product.price,
     box: product.box,
     key: 'index'
}))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文