[英]all the values of clearAllSearchCriteria should be passed to NoResult component
當我單擊Clear All Search Criteria div時,所有clearAllSearchCriteria的值都應傳遞到NoResult組件,然后從那里將值傳遞給Sports-search-favorites-tab.js
我使用下面的鏈接並實現了,但出現錯誤TypeError:_this.alfoRef.handleDeleteFromParent不是函數。 在reactjs中從父級調用子級函數
TypeError:_this.alfoRef.handleDeleteFromParent不是函數
祖父組件1 Sports-search-favorites-tab.js
import SportsCardList from './SportsCardList';
clearAllSearchCriteria = () => {
console.log('clearAllSearchCriteria');
this.alfoRef.handleDeleteFromParent();
}
render() {
const { classes } = this.props;
return (
<Card className={classes.card}>
<CardContent style={{ paddingTop: 0, paddingBottom: 0 }}>
<Typography className={classes.noResultContainer}>
{/*<div className={classes.noResultContainer}>*/}
<div className={classes.noResultContainerItemText}>No Results Were Returned</div>
<CardActions className={classes.noResultContainerItem}>
<div className={classes.clearAll} onClick={this.props.clearAllSearchCriteria} >Clear All Search Criteria</div>
{/*<div onClick={() => props.clicked(clearAllSearchVar)}/>*/}
{/*<div onClick={() => props.clicked(clearAllSearchCriteria)}> Clear All Search Criteria</div>*/}
</CardActions>
{/*
<CardActions className={classes.noResultContainerItem}>
<Button onClick={this.toggleDrawer("right", true)} size="small">Create task for Custom Payment Build</Button>
</CardActions>*/}
{/*</div>*/}
</Typography>
</CardContent>
<Drawer
style={{ width: 500 }}
anchor="right"
open={this.state.right}
onClose={this.toggleDrawer("right", false)}
>
<div
tabIndex={0}
role="button"
>
{/*sideList*/}
{/*sports advanced search for tab codes */}
<TabDemo />
</div>
</Drawer>
</Card>
);
}
父級1(中間component2)SportsCardList.js
import NoResult from './no-result';
clearAllSearchCriteria = () =>{
console.log('clearAllSearchCriteria');
this.props.clearAllSearchCriteria();
}
<NoResult clearAllSearchCriteria={this.clearAllSearchCriteria}/>
子級(孫子)組件3 no-result.js
return (
<Card className={classes.card}>
<CardContent style={{ paddingTop: 0, paddingBottom: 0 }}>
<Typography className={classes.noResultContainer}>
{/*<div className={classes.noResultContainer}>*/}
<div className={classes.noResultContainerItemText}>No Results Were Returned</div>
<CardActions className={classes.noResultContainerItem}>
<div className={classes.clearAll} onClick={this.props.clearAllSearchCriteria} >Clear All Search Criteria</div>
{/*<div onClick={() => props.clicked(clearAllSearchVar)}/>*/}
{/*<div onClick={() => props.clicked(clearAllSearchCriteria)}> Clear All Search Criteria</div>*/}
</CardActions>
{/*
<CardActions className={classes.noResultContainerItem}>
<Button onClick={this.toggleDrawer("right", true)} size="small">Create task for Custom Payment Build</Button>
</CardActions>*/}
{/*</div>*/}
</Typography>
</CardContent>
</Card>
);
祖父組成部分 :
clearAllHandler = (clearAllSearchVar) => {
// Work with clearAllSearchVar
}
<Father clicked={this.clearAllHandler} />
父親組成部分 :
<Son clicked={props.clicked} />
子組件 :
<div onClick={() => props.clicked(clearAllSearchVar)}/>
應填寫clearAllSearchVar
在<Son />
組件,每當你點擊它的變量傳遞給clearAllHandler
函數<Grandfather />
組件,它傳遞給函數的引用到他的盛大 <Son />
經由道具<Father />
。
希望有幫助!
祖父:
import SportsCardList from './SportsCardList';
clearAllSearchCriteria = (clearAllSearchVar) => {
//Work here with clearAllSearchVar
console.log('clearAllSearchCriteria');
this.alfoRef.handleDeleteFromParent();
}
<div>
{/*<NoResult />*/}
<SportsCardList clicked={this.clearAllSearchCriteria}/>
<Dialog
isOpen={this.state.open}
onClose={() => {
this.setState({ open: false });
}}
/>
</div>
父親 SportsCardList.js:
const SportsCardList = props => {
<NoResult clicked={props.clicked}/>
}
兒子 NoResult.js:
const NoResult = props => {
<CardActions className={classes.noResultContainerItem}>
<div className={classes.clearAll} onClick={() => props.clicked(clearAllSearchCriteria)} >Clear All Search Criteria</div>
</CardActions>
}
只要確保您填寫clearAllSearchCriteria變量即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.