Picker示例给出TypeError

时间:2018-10-26 12:52:57

标签: javascript react-native react-native-android picker

我从手册中复制粘贴了一个Picker示例,但我不断收到以下错误:

  

TypeError:TypeError:TypeError:无法读取未定义的属性“值”

     

此错误位于:       在PickerAndroid中(在Picker.js:158)       在Picker中(在NewNotification.js:32)       在RCTView中(在View.js:60)       在视图中(在KeyboardAvoidingView.js:196处)       在KeyboardAvoidingView中(在NewNotification.js:23处)       在NewNotification中(在SceneView.js:9)       在SceneView中(位于StackViewLayout.js:478)       在RCTView中(在View.js:60)       在视图中(位于StackViewLayout.js:477)       在RCTView中(在View.js:60)       在View中(在StackViewLayout.js:476)       在RCTView中(在View.js:60)       在View中(在createAnimatedComponent.js:154处)       在AnimatedComponent中(在screens.js:51)       在屏幕上(在StackViewCard.js:42上)       在Card中(在createPointerEventsContainer.js:26处)       在容器中(位于StackViewLayout.js:507)       在RCTView中(在View.js:60)       在View中(在screens.js:76)       在ScreenContainer中(在StackViewLayout.js:401处)       在RCTView中(在View.js:60)       在View中(在StackViewLayout.js:400处)       在StackViewLayout中(位于withOrientation.js:30)       在withOrientation中(在StackView.js:49处)       在RCTView中(在View.js:60)       在视图中(在Transitioner.js:141)       在Transitioner中(位于StackView.js:19)       在StackView中(位于createNavigator.js:57)       在导航器中(位于createKeyboardAwareNavigator.js:11处)       在KeyboardAwareNavigator中(位于createNavigationContainer.js:376)       在NavigationContainer中(在App.js:23)       在App中(在registerRootComponent.js:35处)       在RootErrorBoundary中(在registerRootComponent.js:34处)       在ExpoRootComponent中(在renderApplication.js:33处)       在RCTView中(在View.js:60)       在View中(在AppContainer.js:102)       在RCTView中(在View.js:60)       在View中(在AppContainer.js:122)       在AppContainer中(位于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"

1 个答案:

答案 0 :(得分:1)

您的代码中有错字

style={styles.picker}>

应该是

style={styles.picker}