我的父元素中有方法,di 將其作為道具傳遞;像這樣:<NavBar retrieveList={this.retrieveList}/>在我的子組件中,我無法從另一個方法體調用此方法。handleCloseModal () { window.$('#newHireModal').modal('hide'); /* this is working */ console.log(this.props.retrieveList); /* it gives method body, just to be sure props is coming here */ this.props.retrieveList; /*it gives "Expected an assignment or function call..." */ this.props.retrieveList(); /*it gives "this.props.retrieveList is not a function" */ return this.props.retrieveList; /*it does nothing. no working, no error. */ }順便說一句,我有構造函數和綁定;constructor(props) { super(props); this.handleCloseModal = this.handleCloseModal.bind(this);retrieveList() { StaffDataService.getAll() .then(response => { this.setState({ staffWithBasics: response.data, filteredItems: response.data, }); }) .catch(e => { console.log(e); }); }這段代碼有什么問題,我該如何運行這個父方法?
在反應中調用作為道具傳遞的方法
牛魔王的故事
2022-12-22 15:49:28