父组件定义方法:
type PageStateProps = {
OrderStore: {
getOrders: Function;
orders: Array<any>;
onAcceipt: Function;
confirmModalState: boolean;
};
onAcceptOrder: Function;
};
onAcceptOrder() {
console.log(this);
}
{orders.map((item) => {
return <OrderItem orderItem={item} key={item.workOrderId} onAcceptOrder={this.onAcceptOrder} />;
})}
};
子组件:
type PageStateProps = {
orderItem: {
workOrderId: string;
workOrderNo: string;
content: string;
createTime: string;
workOrderStatus: number;
createUserName: string;
acceptUserName: string;
productName: string;
productClassificationName: string;
};
onAcceptOrder: Function;
onAcceptOrder = () => {
console.log(this);
this.props.onAcceptOrder();
};
<AtButton className='btn-accept' onClick={this.onAcceptOrder}>接单</AtButton>
点击"接单"按钮以后会报this.props.onAcceptOrder is not a function,打印this.props中也没有onAcceptOrder这个方法。
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…