React fixed-data-table: Uncaught ReferenceError: Table is not defined

React fixed-data-table: Uncaught ReferenceError: Table is not defined

我将 React 与 bootstrap 模板一起用于前端目的。我打算在面板中使用 fixed-data-table。在标记中调用函数会导致浏览器出现以下错误:

Uncaught ReferenceError: Table is not defined
    at t.render (eval at n.run (babel.5.8.38.browser.min.js:3), <anonymous>:1059:13)
    at p._renderValidatedComponentWithoutOwnerOrContext (react.min.js:13)
    at p._renderValidatedComponent (react.min.js:13)
    at performInitialMount (react.min.js:13)
    at p.mountComponent (react.min.js:13)
    at Object.mountComponent (react.min.js:15)
    at h.mountChildren (react.min.js:14)
    at h._createInitialChildren (react.min.js:13)
    at h.mountComponent (react.min.js:13)
    at Object.mountComponent (react.min.js:15)

固定数据-table.js在我的index.html中为

<script src="script/lib/fixed-data-table.min.js"></script>

虽然我也为它添加了 .css 文件。

这是 table 创建的反应 class:

var TestTable = React.createClass({
    getInitialState: function () {
        return {data :  {
            rows: [
                {
                    "street": "Road",
                    "number": "33",
                    "postalCode": "5000",
                    "city": "Town 3",
                    "country": "Country1"
                },
                {
                    "street": "Road",
                    "number": "333",
                    "postalcode": "5000",
                    "city": "Town 1",
                    "country": "Country 2"
                },
                {
                    "street": "Road",
                    "number": "31",
                    "postalCode": "5500",
                    "city": "Town 2",
                    "country": "Country 3"
                }]
        }};
    },


    render() {

        return <Table
            height={40 + ((this.state.data.rows.length + 1) * 30)}
            width={1150}
            rowsCount={this.state.data.rows.length}
            rowHeight={30}
            headerHeight={30}
            rowGetter={function (rowIndex) {
                return this.state.data.rows[rowIndex];
            }.bind(this)}>
            <Column dataKey="street" width={100} label="Address"/>
            <Column dataKey="number" width={100} label="Number"/>
            <Column dataKey="postalcode" width={100} label="Postal Code"/>
            <Column dataKey="city" width={400} label="City"/>
            <Column dataKey="country" width={50} label="Country"/>
        </Table>;

    },
});

我在一个元素中将它称为 <TestTable />,然后在调用时会产生上述错误。

似乎它不接受固定数据-table.min.js,即使它像其他组件一样定义并加载在 index.html 中?

编辑:我试图在函数之前直接导入...现在的结果是:import {Table, Column, Cell} from "./script/lib/fixed-data-table.min.js";

Uncaught ReferenceError: require is not defined
    at eval (eval at n.run (babel.5.8.38.browser.min.js:3), <anonymous>:4:37)
    at Function.n.run (babel.5.8.38.browser.min.js:3)
    at l (babel.5.8.38.browser.min.js:3)
    at babel.5.8.38.browser.min.js:3
    at XMLHttpRequest.s.onreadystatechange (babel.5.8.38.browser.min.js:3)

您可以尝试install it via an npm package然后在您的组件中使用它。

安装运行命令

npm install -S fixed-data-table

并像这样导入它

import {Table, Column, Cell} from 'fixed-data-table';

这应该适合你

另外,正如文档所建议的,您应该添加默认样式表 dist/fixed-data-table.css