[英]How to add href to react-bootstrap-table column dynamically?
[英]How to navigate between Components in react from button under react-bootstrap-table 2 column
我正在使用 React Bootstrap 表 2 來顯示來自外部 API 的數據。 作為我表的一部分,我包含了一個虛擬列,它為每一行存儲一個按鈕,單擊時應該導航到帶有一些行信息的不同組件。
我的代碼中的列定義:
{
dataField: 'expand',
text: 'EXPAND',
isDummyField:true,
editable: false,
formatter: (cell, row, rowIndex, formatExtraData) =>
{
return (
<button
type="button"
onClick = {() => <ExtendedView data={row} /> }
>
<img src = {expand} alt="expand"></img>
</button>
);
},
headerStyle: () =>
{
return { width: '50px', textAlign: 'center' };
}
}
按鈕單擊應重定向到的組件:
import React from 'react';
class ExtendedView extends React.Component
{
constructor(props)
{
super(props)
this.state =
{
Id:0
}
}
render()
{
console.log(this.props.data)
console.log(this.state.Id)
return(
<div>
<h1>{this.props.data}</h1>
</div>
);
}
}
export default ExtendedView;
我沒有收到任何錯誤,也無法導航到子組件。 作為兩個 console.log() 命令的一部分,也沒有打印任何內容我不確定反應實際發生了什么,或者我錯過了一些東西。
這可能是一個非常簡單的問題,但作為一個新手,我無法調試。
請幫忙。
謝謝...
問題在於代碼onClick = {() => <ExtendedView data={row} /> }
如果您想要將視圖更改為 ExtendedView,那么您必須使用庫來控制不同的視圖,因為 React 旨在創建 SPA。 在這種情況下,我使用庫 react-router ( https://reacttraining.com/react-router/web/example/basic )。 易於使用,可以幫助您解決這個問題
我使用彈出的概念解決了它。 制作一個組件並根據事件觸發器切換它的顯示
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.