我使用coreui CDataTable来呈现一个表。
return (
<CDataTable
items={data}
fields={fields}
...
/>
)
一切都进展顺利。但是,我需要在CDataTable组件的标题中添加一个按钮,用于下载客户端的excel文件。我注意到CDataTable没有在表头中添加额外按钮的功能,所以我决定直接编辑节点包。据我所知。组件在两个文件中被引用
在index.d.ts中:
interface CDataTable {
...
loadingSlot?: ChildElement;
loading?: boolean;
fields?: Array<any>;
...
}
在CDataTable.js里
var CDataTable = function CDataTable(props) {
var _ref2;
var innerRef = props.innerRef,
overTableSlot = props.overTableSlot,
columnHeaderSlot = props.columnHeaderSlot,
sortingIconSlot = props.sortingIconSlot,
........
我使用他们的CButton
组件在报头中添加了一个额外的按钮,并给该按钮一个onClick函数:
React.createElement(CButton, {
className: "btn btn-primary mfe-2 excel-button",
onClick: function onClick(e) {
excelFunc(e)
}
}, "Excel indir")
var excelFunc = function excelFunc() {
excelButton && excelButton()
}
我还分别将此函数添加到了各种类型中:
excelButton = props.excelButton;
excelButton: PropTypes.func
以及在TS文件中
excelButton?: Function;
按钮正确呈现。然而,当我传递一个简单的函数时,道具:
...
excelButton = {() => console.log("hi")}
我得到一个错误,它说excelButton没有定义。这里有什么问题?
发布于 2021-06-27 15:32:36
在尝试不同的方法之后..。
props.excelButton; = excelButton
PropTypes.func:excelButton
excelButton
作为函数:React.createElement(CButton,{ className:"btn主mfe-2 Excel-按钮“),onClick:函数onClick() { excelButton() },"Excel”)
https://stackoverflow.com/questions/68150980
复制相似问题