我正在使用 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() 命令的一部分,沒有任何內容被打印出來,我不確定反應實際上發生了什么,或者我錯過了一些東西。這可能是一個非常簡單的問題,但作為 React 的新手我無法調試。
如何在 react-bootstrap-table 2 列下的按鈕中在組件之間導航
阿波羅的戰車
2022-12-29 16:26:11