我有一個包含設置視圖的NavigatorIOS組件。在該設置視圖中是一個設置列表,單擊打開它們自己的視圖。當點擊該設置,向後箭頭和右按鈕出現,就像這樣: 如何獲取NavigatorIOS的子組件TextInput的反應原生的值
我有當按下右邊的按鈕稱爲onRightButtonPress
的功能集是我的導航器的push
功能,這是一種內從設置頁面調用以將設置頁面綁定到子項。我push
功能如下:
navHeight(){
this.props.navigator.push({
title: 'Height',
component: Height,
rightButtonTitle: 'Save',
passProps: {
units: this.state.units
},
onRightButtonPress:() => {
console.warn("hey whats up hello");
this.props.navigator.pop()}
})
}
認爲呈現的是一個孩子的身高組件看起來是這樣的:
class Height extends Component{
render(){
return(
<View style={styles.settingInput}>
<Text style={styles.inputRow}>Height: </Text>
<TextInput ref="heightInput"
onChangeText={function(text){
console.warn(text);
}
}/>
<Text style={styles.inputRowRight}> m</Text>
</View>
);
}
}
有沒有什麼辦法的時候訪問TextInput
的價值在Height
組件onRightButtonPress
叫做?如果有幫助,我的反應原生版本是0.27.2。
編輯:我特別只想訪問按下保存按鈕時寫入TextInput內部的文本。基本上,我不希望任何傳遞給孩子的道具被更新,除非它被按下。
你可以將'onRightButtonPress.bind(this)'傳遞給_Height_,所以你可以像'onChangeText = {function(text){this.props.onRightButtonPress(text);}}'' – Siou
那樣使用它哦,但是我特別需要在按下rightButton之前不要調用onRightButtonPress。每次更改文本時都會調用onRightButtonPress。 – zavtra