showConfirm() {//弹出确认对话框
confirm({
title: '当前总计应收金额为'+this.state.allReceivablePrice+'元',//这里能得到值!!!!
// content: 'some descriptions',
okText: '确认回款',
cancelText: '取消',
onOk() {
const {allSelectOrder}=this.state;
if (allSelectOrder.length==0){
message.error('订单Id不能为空');
return;
}else {
this.setState({loading: true});
$.ajax({
url: API.flow,
type: 'post',
dataType: 'json',
data: JSON.stringify(allSelectOrder),
contentType: 'application/json;charset=UTF-8',
success: ()=> {
this.setState({
loading: false,
});
message.success('添加收款记录成功!');
this.refreshData();
},
error: (data)=> {
Modal.error({
title: data.responseJSON.msg
});
this.setState({ loading: false });
}
})
}
},
onCancel() {
},
});
},
Why can’t I get this, I have added bind
Error:
PaymentCollection.jsx:329 Uncaught TypeError: Cannot read property 'state' of undefined
Your ajax success and error are not bound. Pay attention to the location of the error message.
To be precise, the this environment of the onOk function has been lost. ;
Thanks for the invitation.
-----Separating line----
Define _this outside showConfirm, and then replace this with _this.