【问题标题】:Regular react table to MaterialTable对 MaterialTable 的常规反应表
【发布时间】:2020-12-01 23:31:25
【问题描述】:

如何在我的材料表中从数组中添加数据?

我有下表:

<table className="table">
    <thead>
        <tr>
            <th>Text1</th>
            <th>Text2</th>
            <th>text3 Comb</th>
        </tr>
    </thead>
    <tbody>
        {arr.map((values, index) => {
            const textComb = `${values.text1}, ${values.text2}`;
            return (
                <tr key={index}>
                    <td>{values.text1}</td>
                    <td>{values.text2}</td>
                    <td>{textComb}</td>
                    <td></td>
                </tr>
            )
        })}
    </tbody>
</table>

我的数据太多,所以我尝试使用 MaterialTable 来进行搜索、排序和分页选项。

<MaterialTable
    columns={[
        {title: 'Text1', field: 'text1'},
        {title: 'Text2', field: 'text2'},
        {title: 'Text3', field: 'text3'}
    ]}
    data={
        arr((values, index) => {
            {
               // I'm confused here
            }
        })
    }
/>

【问题讨论】:

    标签: reactjs material-table


    【解决方案1】:

    试试这个-

    const createData = item => ({
        text1: item.text1,
        text2: item.text2,
        text3: `${item.text1}, ${item.text2}`
    });
    
    const data = arr.map(item => createData(item));
    

    在这里查看演示 - https://codesandbox.io/s/material-table-example-5cohx?file=/src/App.js

    【讨论】:

    • 返回TypeError: _this.props.data(...).then is not a function
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-14
    • 2010-10-06
    • 1970-01-01
    • 2020-12-18
    • 2016-09-11
    • 2020-10-18
    • 1970-01-01
    相关资源
    最近更新 更多