我有一个反应应用程序,它会产生错误
警告: React.createElement: type不应为空、未定义、布尔或数字。它应该是一个字符串(用于DOM元素)或一个ReactClass (用于组合组件)。检查
BasicDataTableExample的呈现方法。
和
未定义错误:元素类型无效:期望字符串(用于内置组件)或类/函数(用于组合组件),但未定义。检查
BasicDataTableExample的呈现方法。
我在Create your Columns区的https://facebook.github.io/fixed-data-table/getting-started.html
区别在于,我使用的是cdn,而他们使用的是
const {Table, Column, Cell} = require('fixed-data-table');而不是。
我试着像const Table = FixedDataTable.Table;一样解压缩,当我进入调试器时,它看起来很有效,但是应用程序坏了。看上去:
<!DOCTYPE html>
<html>
<head>
<title>data-table-basic</title>
<script src="https://unpkg.com/react@15.3.2/dist/react.js"></script>
<script src="https://unpkg.com/react-dom@15.3.2/dist/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-router/4.0.0-beta.3/react-router.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fixed-data-table/0.6.3/fixed-data-table.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/fixed-data-table/0.6.3/fixed-data-table.min.css" rel="stylesheet">
<head>
<body>
<a class="nav-link" href="/clock">clock</a>
<a class="nav-link" href="/counter">counter</a>
<a class="nav-link" href="/data-table-basic">data-table-basic</a>
<a class="nav-link" href="/query-params-react-router">query-params-react-router</a>
<a class="nav-link" href="/todo-list">todo-list</a>
<a class="nav-link" href="/validated-form">validated-form</a>
<div id="entry"></div>
<div id="code"></div>
<script type="text/babel">
var destination = document.querySelector("#entry");
const Table = FixedDataTable.Table;
const Column = FixedDataTable.Column;
const Cell = FixedDataTable.cell;
class BasicDataTableExample extends React.Component {
constructor(props) {
super(props);
this.state = {
myTableData: [
{name: 'Rylan'},
{name: 'Amelia'},
{name: 'Estevan'},
{name: 'Florence'},
{name: 'Tressa'},
],
};
}
render() {
return (
<Table
rowsCount={this.state.myTableData.length}
rowHeight={50}
headerHeight={50}
width={1000}
height={500}>
<Column
header={<Cell>Name</Cell>}
cell={props => (
<Cell {...props}>
{this.state.myTableData[props.rowIndex].name}
</Cell>
)}
width={200}
/>
</Table>
);
}
}
ReactDOM.render(
<div>
<BasicDataTableExample/>
</div>,
destination
)
</script>
</body>
</html>如何使Table、Column和Cell像使用cdn那样正确显示?
发布于 2017-01-31 19:45:22
这里的问题很可能是Cell是undefined,因为您试图将它检索为
const Cell = FixedDataTable.cell;,而属性以大写C开头。
const Cell = FixedDataTable.Cell;发布于 2017-01-31 19:47:26
如果您正在使用CDN,那么将您的函数封装到IIFE中:
(function() {
//your code will be executed after window load
})();发布于 2017-01-31 19:47:38
蒂莫是对的。但不是
const Table = FixedDataTable.Table;
const Column = FixedDataTable.Column;
const Cell = FixedDataTable.Cell;导入模块时,可以使用
import {Table, Column, Cell} from 'fixed-data-table';少敲击键盘。
https://stackoverflow.com/questions/41966131
复制相似问题