Reactjs 反应,将值从父级传递给两个不同的子级
从父组件传递值。它适用于导航组件,但不适用于文本组件。嵌套的返回和循环将不允许传递值Reactjs 反应,将值从父级传递给两个不同的子级,reactjs,react-native,foreach,Reactjs,React Native,Foreach,从父组件传递值。它适用于导航组件,但不适用于文本组件。嵌套的返回和循环将不允许传递值 <div className="container"> { currentpage.map((rows, i) => { return ( <div key={i} className="row">
<div className="container">
{
currentpage.map((rows, i) => {
return (
<div key={i} className="row">
<Nav editModeState={this.state.editModeState} /> //This editModeState is working fine.
{rows.row.map(function (component, i) {
return <div className="col-lg-4">
<div key={i} className="card" key={i}>
<div className="card-body">
<TextComponent
componentFromParent = {component}
editModeState={this.state.editModeState} //The value is not passing, but it is working for <Nav editModeState={this.state.editModeState} /> component
/>
</div>
</div>
</div>
})}
</div>
);
})
}
</div>
错误
TypeError:无法读取未定义的属性“状态”
这里的函数绑定问题<代码>未正确绑定到映射函数
有两种方法可以解决此问题: 使用胖箭头语法(=>) 使用fat arrow函数(此处使用的方式是
currentpage.map((行,i)=>{
)修复错误
{rows.row.map((component, i) => { /* Your code here */ })}
提供此映射函数 map函数接受第二个参数
this
。因此代码将被修改为:
{rows.row.map(function(component, i) { /* Your code here */ }, this)}
它表示TypeError:无法读取未定义的.constructor()的属性“state”{super();this.state={editModerate:}}fromnaveditor(params){this.setState({editModerate:params})}
{rows.row.map(function(component, i) { /* Your code here */ }, this)}