简体   繁体   English

为什么数据没有显示在 react-bootstrap-table 中?

[英]Why data not displaying in the react-bootstrap-table?

I want to display a raw data in the react-bootstrap-table.我想在 react-bootstrap-table 中显示原始数据。 The data which i am passing as property in the bootstrap table is displaying properly in the console but it is not displaying in the table respected rows.我在引导表中作为属性传递的数据在控制台中正确显示,但未在表中显示的行中显示。

The function from which i am getting records.我从中获取记录的 function。

displayRecords = () => {
    var listAllRecords = this.props.data
    return (
    listAllRecords.map((listRecord,index) => {
        console.log(listRecord)
        listRecord.subData.map((singleData,index) => {
            console.log('singleData:' +index,singleData)
            return singleData.name
        })
    }) )
}

Bootstrap table in which i want dislpay those records.我想在其中显示这些记录的引导表。

<BootstrapTable ref='table' data={this.props.data}>
<TableHeaderColumn dataField='records' dataFormat={this.displayRecords}>Record</TableHeaderColumn>
</BootstrapTable>

Result of console.log(listRecord) console.log(listRecord)的结果

Table Row1: { 
subData: Array(2)
0: {id: 1, name: "data1"}
1: {id: 2, name: "data2"}
id: 2
image: null
name: "John"
}
Table Row2:{ 
subData: Array(3)
0: {id: 1, name: "data1"}
1: {id: 2, name: "data2"}
2: {id: 3, name: "data3"}
id: 3
image: null
name: "Doe"
}

console log of singleData singleData 的控制台日志

singleData: 0 {id: 2, name: "data"}
singleData: 1 {id: 3, name: "data1"}

singleData: 0 {id: 2, name: "data"}
singleData: 1 {id: 3, name: "data1"}

singleData: 0 {id: 2, name: "data"}
singleData: 1 {id: 3, name: "data1"}
singleData: 2 {id: 4, name: "data1"}

PS: There are three rows records. PS:一共有三行记录。

So, i want to display records in the table rows as the respected row wise like in the first row it should be display "data1, data2" and in the second row it shoud be display "data1,data2,data3"所以,我想在表行中显示记录作为受尊重的行,就像在第一行它应该显示"data1, data2" ,在第二行它应该显示"data1,data2,data3"

Try this lines of code:- 1. Make a state:-试试这行代码:- 1. 制作一个 state:-

this.state = {
     dataList:[]
}

2. Add this in render() function:- 2.在render()中添加这个function:-

<BootstrapTable data={dataList}>
    <TableHeaderColumn isKey dataField='id'>ID</TableHeaderColumn>
    <TableHeaderColumn dataField='name'>Name</TableHeaderColumn>
</BootstrapTable>

3. Modify displayRecords() method:- 3.修改displayRecords()方法:-

displayRecords = () => {
        var listAllRecords = this.props.data
        listAllRecords.map((listRecord,index) => {
            console.log(listRecord)
            this.setState({
                 dataList: listRecord
            })
            listRecord.subData.map((singleData,index) => {
                console.log(singleData)            
                singleData.name
            })
        })
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM