我的父元素中有方法,di 将它作为props传递;像这样:
<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);
});
}
这段代码有什么问题,我该如何运行这个父方法?