React fixed-data-table:Uncaught ReferenceError:未定义表

时间:2016-12-22 13:19:26

标签: javascript reactjs fixed-data-table

我正在将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)

fixed-data-table.js在我的index.html中作为

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

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

这是表创建的反应类:

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 />中调用它,然后在调用时产生上述错误。

似乎它没有接受fixed-data-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)

1 个答案:

答案 0 :(得分:1)

您可以尝试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