如何将列的内容传递到 react-bootstrap-table2 中的 dummyField
How to pass the content of your columns to a dummyField in react-bootstrap-table2
我正在尝试将列数据字段的值传递到 react-bootstrap-table2 dummyField 中的按钮。我不太清楚该怎么做。这是我的列数据字段。
const columns = [
{
dataField: "firstName",
text: "First Name",
},
{
dataField: "middleName",
text: "Middle Name",
},
{
dataField: "lastName",
text: "Last Name",
},
{
dataField: "sex",
text: "Sex",
sort: true,
},
{
dataField: "rootChapter",
text: "Root Chapter",
},
{
dataField: "municipalCouncil.name",
text: "Council",
sort: true,
},
{
dataField: "batchName",
text: "Batch Name",
sort: true,
},
{
dataField: "alias",
text: "Alias",
},
{
dataField: "actions",
text: "Actions",
isDummyField: true,
formatter: (cell, row) => <MemberButtons member={columns} id={row._id} />, // Overhere is the problem
},
];
我这样做是因为模态。我是 React.js 的初学者,特别是 react-bootstrap-table2.
第一种方法:使用状态将其传递给您的组件
export default class yourClassName extends Component{
constructor(props){
super(props);
this.state = {
columns: [ your array data here ]
}
render(){
<yourTable/>
}
}
第二种方法:你可以使用 State Hook https://reactjs.org/docs/hooks-state.html
两种方法都会产生相同的结果,您可以选择适合您的编码风格的一种。
所以这样做是可行的
{
dataField: "actions",
text: "Actions",
isDummyField: true,
formatter: (cell, row) => <MemberButtons values={row} id={row._id} />, // By passing row variable to values I got all the contents of my datafields
},
感谢那些试图帮助我的人。如果您找到了更好的方法,请不要犹豫,post 在这里。谢谢 :)
我正在尝试将列数据字段的值传递到 react-bootstrap-table2 dummyField 中的按钮。我不太清楚该怎么做。这是我的列数据字段。
const columns = [
{
dataField: "firstName",
text: "First Name",
},
{
dataField: "middleName",
text: "Middle Name",
},
{
dataField: "lastName",
text: "Last Name",
},
{
dataField: "sex",
text: "Sex",
sort: true,
},
{
dataField: "rootChapter",
text: "Root Chapter",
},
{
dataField: "municipalCouncil.name",
text: "Council",
sort: true,
},
{
dataField: "batchName",
text: "Batch Name",
sort: true,
},
{
dataField: "alias",
text: "Alias",
},
{
dataField: "actions",
text: "Actions",
isDummyField: true,
formatter: (cell, row) => <MemberButtons member={columns} id={row._id} />, // Overhere is the problem
},
];
我这样做是因为模态。我是 React.js 的初学者,特别是 react-bootstrap-table2.
第一种方法:使用状态将其传递给您的组件
export default class yourClassName extends Component{
constructor(props){
super(props);
this.state = {
columns: [ your array data here ]
}
render(){
<yourTable/>
}
}
第二种方法:你可以使用 State Hook https://reactjs.org/docs/hooks-state.html
两种方法都会产生相同的结果,您可以选择适合您的编码风格的一种。
所以这样做是可行的
{
dataField: "actions",
text: "Actions",
isDummyField: true,
formatter: (cell, row) => <MemberButtons values={row} id={row._id} />, // By passing row variable to values I got all the contents of my datafields
},
感谢那些试图帮助我的人。如果您找到了更好的方法,请不要犹豫,post 在这里。谢谢 :)