Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 反应,将值从父级传递给两个不同的子级_Reactjs_React Native_Foreach - Fatal编程技术网

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)}