Picker 示例给出了 TypeError
我从手册中复制粘贴了一个
Picker
示例,但不断收到以下错误:
TypeError: TypeError: TypeError: Cannot read property 'value' of undefined
This error is located at: in PickerAndroid (at Picker.js:158) in Picker (at NewNotification.js:32) in RCTView (at View.js:60) in View (at KeyboardAvoidingView.js:196) in KeyboardAvoidingView (at NewNotification.js:23) in NewNotification (at SceneView.js:9) in SceneView (at StackViewLayout.js:478) in RCTView (at View.js:60) in View (at StackViewLayout.js:477) in RCTView (at View.js:60) in View (at StackViewLayout.js:476) in RCTView (at View.js:60) in View (at createAnimatedComponent.js:154) in AnimatedComponent (at screens.js:51) in Screen (at StackViewCard.js:42) in Card (at createPointerEventsContainer.js:26) in Container (at StackViewLayout.js:507) in RCTView (at View.js:60) in View (at screens.js:76) in ScreenContainer (at StackViewLayout.js:401) in RCTView (at View.js:60) in View (at StackViewLayout.js:400) in StackViewLayout (at withOrientation.js:30) in withOrientation (at StackView.js:49) in RCTView (at View.js:60) in View (at Transitioner.js:141) in Transitioner (at StackView.js:19) in StackView (at createNavigator.js:57) in Navigator (at createKeyboardAwareNavigator.js:11) in KeyboardAwareNavigator (at createNavigationContainer.js:376) in NavigationContainer (at App.js:23) in App (at registerRootComponent.js:35) in RootErrorBoundary (at registerRootComponent.js:34) in ExpoRootComponent (at renderApplication.js:33) in RCTView (at View.js:60) in View (at AppContainer.js:102) in RCTView (at View.js:60) in View (at AppContainer.js:122) in AppContainer (at renderApplication.js:32)
我的代码如下所示:
state = {
location: 'a'
}
render(){
return(
<Picker
selectedValue={this.state.location}
style={styles.picker}>
onValueChange={(itemValue, itemIndex) => this.setState({location: itemValue})}>
<Picker.Item label="a" value="a" />
<Picker.Item label="b" value="b" />
<Picker.Item label="c" value="c" />
<Picker.Item label="d" value="d" />
</Picker>
)
更多信息:
"expo": "^30.0.1",
"react": "16.3.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-30.0.0.tar.gz",
"react-navigation": "^2.18.1"
您的代码中有一个拼写错误
style={styles.picker}>
应该是
style={styles.picker}