Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.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 React Native-setNativeProps()对parentElement.props.children=未定义_Reactjs_React Native_Jsx - Fatal编程技术网

Reactjs React Native-setNativeProps()对parentElement.props.children=未定义

Reactjs React Native-setNativeProps()对parentElement.props.children=未定义,reactjs,react-native,jsx,Reactjs,React Native,Jsx,我正在为自己开发一个学校管理应用程序。 我班上所有的学生都列在一个简单的名单上,旁边有他们父母的电话号码,这样我可以在学生缺席时给他们发短信 我有一个包含Listitems的平面列表,每个列表都包含一个包含文本子级的Touchopacity组件 成功向学生家长发送短信后(smsParent方法),我想在TouchOpacity及其文本子级上设置NativeProps(操纵它们的样式道具)。我使用ref=(()=>…)引用Touchopacity,然后使用this.props.children(仅

我正在为自己开发一个学校管理应用程序。 我班上所有的学生都列在一个简单的名单上,旁边有他们父母的电话号码,这样我可以在学生缺席时给他们发短信

我有一个包含Listitems的平面列表,每个列表都包含一个包含文本子级的Touchopacity组件

成功向学生家长发送短信后(smsParent方法),我想在TouchOpacity及其文本子级上设置NativeProps(操纵它们的样式道具)。我使用ref=(()=>…)引用Touchopacity,然后使用this.props.children(仅1个子项)访问其文本子项

然而,我不能使用setNativeProps(=未定义)。 然而,当我在文本上使用ref=(()=>…)并引用它时,setNativeProps在其父级/的情况下工作/类似

当parentEl.props.children引用一个子项时,为什么不能对它使用setNativeProps()?(只有一个子项,在调试器中签入,它被正确标识)

请阅读smsParent方法中的注释

/*很抱歉插入了一个代码段-代码插入的格式太疯狂了/

/**代码简化/

类SingleClassPage扩展组件{
按钮=新数组();
建造师(道具){
超级(道具);
this.state={students:[]};
this.smsParent=this.smsParent.bind(this);
}
componentDidMount(){
//从api和setState获取学生。。
这个。_getStudentsList();
}
_getStudentsList(){
// ...
}
//平面列表项
李斯特(道具){
返回(
{设a=props.item.attId+'att';props.buttons[a]=el;}
style={[styles.buttonDef,(props.item.phone_parent?styles.buttonBlue:styles.buttonGray)]}
onPress={()=>{props.smsSendHandler(props.item,'attention',a)}>
{props.item.smsAttSent?'sms send':'sms send'}
)
}
render(){
返回(
item.attId}
renderItem={({item})=>}
/>
);
}
smsParent(学生、MSG类别、smsButton){
//调用myjava模块,并在成功回调后调用以下内容:
让parEl=this.butions[smsButton];
//childEl是一个带有props.children的对象,当我在调试器中查看它的值时,它被设置为文本“sms sent/send”
//所以它被正确识别了
let childEl=parEl.props.children;
//工作
parEl.setNativeProps({style:{backgroundColor:'green'}});
//哎呀
setNativeProps({style:{color:'black'}});
}

}
我认为您必须遍历所有子项才能向它们传递nativeProps(即使只有一个子项):


我想发布一个截图。因为我不能在评论中这样做,所以我编辑了qs。
smsParent(student, msgCategory, smsButton) {

    //call myjava module and upon successful callback call below:

    let parEl = this.buttons[smsButton];

    React.Children.forEach(parEl.props.children, child => { child.setNativeProps({ style: { color: 'black' } }) });

    parEl.setNativeProps({ style: { backgroundColor: 'green' } });

  }