Javascript 未捕获的TypeError:无法在onClick React读取未定义的属性“OpenModel”
我越来越Javascript 未捕获的TypeError:无法在onClick React读取未定义的属性“OpenModel”,javascript,reactjs,modal-dialog,Javascript,Reactjs,Modal Dialog,我越来越 Uncaught TypeError: Cannot read property 'openModal' of undefined at onClick 使用以下反应组件: class ReactReduxTabs extends React.Component { constructor(props){ super(props); this.openModal = this.openModal.bind(this); t
Uncaught TypeError: Cannot read property 'openModal' of undefined
at onClick
使用以下反应组件:
class ReactReduxTabs extends React.Component {
constructor(props){
super(props);
this.openModal = this.openModal.bind(this);
this.closeModal = this.closeModal.bind(this);
this.render_response_json_modal = this.render_response_json_modal.bind(this);
this.state = {tabIndex: 1, isModelOpen: false, modalText: "blah blah blah"};
}
openModal() {
console.log("open modal");
this.setState({ isModalOpen: true })
}
closeModal() {
this.setState({ isModalOpen: false })
}
render_response_json_modal(headers, target_header) {
return add_rendering(
headers,
target_header,
function(val, row) {
return (<p onClick={() => {this.openModal()} }>yaaaaaaa</p>)
}
)
}
render() {
if (orderMetricsFetched == true) {
order_metrics.error_report_failed_orders.headers = this.render_response_json_modal(order_metrics.error_report_failed_orders.headers, 'RESPONSE', this.openModal)
return (
<div className="card">
<ReduxDataTable data={order_metrics.error_report_failed_orders}/>
</div>
如果您的目标标题1更改为
headers= [
{title: 'Header 1', render: function() { ...returns what should go in the table cell...} },
'Header 2'
]
问题似乎在于单击表单元格时的上下文。单击表单元格时,它应该调用组件的OpenModel方法
好的新特性是它非常接近,表按它应该的方式呈现,每个响应列单元格内部都有随机的“yaaaaa”,这证明了render\u RESPONSE\u json\u model的add\u呈现是有效的。在我单击每个响应单元格(其中一个为“yaaaa”)之前,不会出现任何错误,我在控制台中看到此打印:
在这里:
顺便说一句,这个异常表示函数中没有定义,可能是因为您使用的是严格模式。您是react之神实际上我从未使用过react,但这个错误在javascript中很常见;
headers= [
{title: 'Header 1', render: function() { ...returns what should go in the table cell...} },
'Header 2'
]
return (<p onClick={() => {this.openModal()} }>yaaaaaaa</p>)
var self = this;
return add_rendering(
headers,
target_header,
function(val, row) {
return (<p onClick={() => {self.openModal()} }>yaaaaaaa</p>)
})
);