给定
import { BootstrapTable, TableHeaderColumn } from 'react-bootstrap-table';
import React from 'react';
var products = [{
id: 1,
name: "Item name 1",
price: 100
},{
id: 2,
name: "Item name 2",
price: 100
},];
var DataTable = React.createClass({
//This is not for-real dynamic. If I can't wrap
//N # of TableHeaderColumn's in a span then I can't solve the problem
generateHeader(){
return (
<span>
<TableHeaderColumn dataField="id" isKey={true} dataAlign="center" dataSort={true}>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField="name" dataSort={true}>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField="price" dataFormat={this.priceFormatter}>Product Price</TableHeaderColumn>
</span>
);
},
// It's a data format example.
priceFormatter(cell, row){
return '<i class="glyphicon glyphicon-usd"></i> ' + cell;
},
render: function() {
return (
<BootstrapTable data={products} striped={true} hover={true}>
<TableHeaderColumn dataField="id" isKey={true} dataAlign="center" dataSort={true}>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField="name" dataSort={true}>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField="price" dataFormat={this.priceFormatter}>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
});
module.exports = DataTable;
我不能打电话generateHeader()
,因为在这种情况下,react 要求我将所有东西都包装在一个父级<span>
中。当我将 TableHeaderColumn 放在 span 内时,BootstrapTable 会中断。
如何生成动态标题?