我有两个道具的父母:实体和选项。我想为每个实体发送选项作为参数。我怎样才能做到这一点?我尝试过:
class FormsList extends React.Component{
constructor(props){
super(props);
};
render(){
var items = this.props.entities.map(function(entity){
return(
<Child data={entity} key={entity.Id} moredata={this.props.options}/>
);
});
return(
<MuiThemeProvider muiTheme={getMuiTheme()}>
<List children={items}/>
</MuiThemeProvider>
);
};
};
我知道在entity.map函数体中无法访问params,但是我应该如何将选项传递给child?
答案 0 :(得分:2)
您需要绑定地图功能,才能访问权限this
。
var items = this.props.entities.map(function(entity){
return (
<Child data={entity} key={entity.Id} moredata={this.props.options}/>
);
}.bind(this);
或者,您可以使用箭头函数语法:
var items = this.props.entities.map(entity => {
return (
<Child data={entity} key={entity.Id} moredata={this.props.options}/>
);
};