2017-05-19 37 views
0

引導表模塊上的數據顯示我的網頁上的一些數據,我想打從相關數據的dataField值的鏈接,這裏有一個片段:如何從相關的數據對象發生反應的自舉表

這裏是我的JSON數據:

{"person": { "name" : "jhon", "personLink" : "jhonlink" },{ "name" : "doe", "personLink" : "doelink" } }

這裏是我的功能代碼:

myLink = (cell) => { 
const urlString = '/person/detail/' + cell; 
return (
    <Link to={urlString} > 
    {cell} 
    </Link> 
)} 

這裏有一個片段我渲染:

<BootstrapTable 
    data={person} 
    striped 
    hover 
    pagination 
    remote 
    > 
    <TableHeaderColumn 
     isKey 
     dataField="name" 
     dataFormat={this.personLink} 
    > 
    Foo 
    </TableHeaderColumn> 
</BootstrapTable> 

是否可以從「personLink」獲取值?因爲我獲得了「名稱」值作爲鏈接。

+0

要提取的personLink價值在哪裏。人也應該是一個陣列的權利? –

+0

我只是編輯我的問題,我想提取「personLink」myLink函數,作爲paremeter(細胞) – user3547367

回答

0

考慮到人的數據處於狀態數據作爲

state= { 
    data: {"person": [{ 
    "name" : "jhon", 
    "personLink" : "jhonlink" 
},{ 
    "name" : "doe", 
    "personLink" : "doelink" 
}] 
} 

在myLink的功能,你可以得到personLink作爲

myLink = (cell) => { 
const urlString = '/person/detail/' + cell; 
var idx = this.state.data.person.findIndex((data) => {return data.name === cell}); 
var personLink = this.state.data.person[idx].personLink 
console.log(personLink); 
return (
    <Link to={urlString} > 
    {cell} 
    </Link> 
)} 

} 
相關問題