Forms 反应本机形式ref为空
我有一个表单Forms 反应本机形式ref为空,forms,react-native,Forms,React Native,我有一个表单productDetails,我想在用户单击按钮Post Your Ad后访问此表单的值 我面临的问题是,我无法访问表单的值。错误是undefined不是对象(计算'this.refs.productDetails.getValue') 我认为出现此错误的原因是this.refs为空。但是我不知道为什么它是空的 非常感谢你的帮助 renderScene(route, navigator) { return ( <View style={styles.body}&g
productDetails
,我想在用户单击按钮Post Your Ad
后访问此表单的值
我面临的问题是,我无法访问表单的值。错误是undefined不是对象(计算'this.refs.productDetails.getValue')
我认为出现此错误的原因是this.refs
为空。但是我不知道为什么它是空的
非常感谢你的帮助
renderScene(route, navigator) {
return (
<View style={styles.body}>
<Form ref="form">
<Text style={{color:'black'}}>Add Photos</Text>
<View style={styles.viewRow}>
<TouchableOpacity onPress={this.selectPhoto.bind(this,0)}>
<View style={{width: 100,marginLeft:5, height: 100, backgroundColor: 'skyblue', marginTop:5}}>
{ arr[0] == null ? <Text></Text> :
<Image style={styles.selectedImage} source={arr[0]} />
}
</View>
</TouchableOpacity>
<TouchableOpacity onPress={this.selectPhoto.bind(this,1)}>
<View style={{width: 100,marginLeft:5, height: 100, backgroundColor: 'skyblue',marginTop:5}}>
{
arr[1] == null ? <Text></Text> :
<Image style={styles.selectedImage} source={arr[1]} />
}
</View>
</TouchableOpacity>
</View>
<View style={styles.viewRow}>
<View style={styles.viewColumn}>
<Text style={{color:'black'}} >Select Category</Text>
<TextInput type="TextInput" name="category"
style={styles.textInputMedium}/>
</View>
<View style={styles.viewColumn}>
<Text style={{color:'black'}}>Price</Text>
<TextInput type="TextInput" name="price"
placeholder='NRs.'
style={styles.textinputSmall}/>
</View>
</View>
<View style={styles.viewColumn}>
<Text style={{color:'black'}}>Title</Text>
<TextInput type="TextInput" name="title"
placeholder='Add Title'
style={{height: 40,width:305, borderColor: 'gray', borderWidth: 1}}/>
</View>
<View style={styles.viewColumn}>
<Text style={{color:'black'}}>Description</Text>
<TextInput type="TextInput" name="description"
placeholder='Add Description'
style={styles.textInputBig}/>
</View>
</Form>
<TouchableHighlight style={styles.submit}
onPress={this.gotoNext.bind(this)}>
<Text style={styles.submitText}>Post Your Ad</Text>
</TouchableHighlight>
</View>
);
}
经过大量的谷歌搜索,我找到了这个问题的解决方案。 问题是我使用了导航器,所以要访问表单的ref,我必须通过导航器的ref来访问它
gotoNext() {
var formObject = this.refs.navigator.refs.form.getValues();
}
gotoNext() {
var formObject = this.refs.navigator.refs.form.getValues();
}