我正在尝试将我的数据绑定到 a blueprint.js
Table
,但是文档不清楚如何执行此操作。如何为 a 创建自定义渲染函数以blueprint.js
Table
从对象列表中渲染键?
在示例rowIndex
中是默认传递的。
编码:
data = [
{ name: "L/S", col2: "abc" },
{ name: "HY", col2: "def" }
];
myRender = (rowIndex: number, key: string) => {
return <Cell> {this.data[rowIndex][key]} </Cell>;
};
<Table numRows={2}>
<Column name="not-working" cellRenderer={this.myRender("name")} />
<Column name="not-working2" cellRenderer={this.myRender("col2")} />
</Table>;
错误:
TypeError
Cannot read property 'undefined' of undefined
18 |
19 | myRender = (rowIndex: number, key: string) => {
> 20 | return <Cell> {this.data[rowIndex][key]} </Cell>;
| ^
21 | };
请参阅此处的示例: https ://codesandbox.io/s/k9l9q2150r