2016-09-15 28 views
1

新的React-Native安裝。我正在設置它。在index.ios.js,我有:React-Native - 找不到變量:標題

class thingy extends Component { 
    render() { 
    return (
     <NavigatorIOS 
     style={styles.container} 
     initialRoute={(
      title: 'Thingy', 
      component: Main 
     )} /> 
    ); 
    } 
} 

當我運行此,應用程序給我的錯誤:

找不到變量:標題

我不知道爲什麼它給了我這個錯誤。有任何想法嗎?

主要成分:

var React = require('react-native'); 

var { 
    View, 
    Text, 
    StyleSheet 
} = React; 

var styles = StyleSheet.create({ 
    mainContainer: { 
    flex: 1, 
    padding: 30, 
    marginTop: 65, 
    flexDirection: 'column', 
    justifyContent: 'center', 
    backgroundColor: '#48BBEC' 
    }, 
    title: { 
    marginBottom: 20, 
    fontSize: 25, 
    textAlign: 'center', 
    color: '#fff' 
    }, 
    searchInput: { 
    height: 50, 
    padding: 4, 
    marginRight: 5, 
    fontSize: 23, 
    bordderWidth: 1, 
    borderColor: 'white', 
    borderRadius: 8, 
    color: 'white' 
    }, 
    buttonText: { 
    fontSize: 18, 
    color: '#111', 
    alignSelf: 'center' 
    }, 
    button: { 
    height: 45, 
    flexDirection: 'row', 
    backgroundColor: 'white', 
    borderColor: 'white', 
    borderWidth: 1, 
    bordeRadius: 8, 
    marginBottom: 10, 
    marginTop: 10, 
    alignSelf: 'stretch', 
    justifyContent: 'center' 
    }, 
}); 

class Main extends React.Component{ 
    render(){ 
    return (
     <View style={styles.mainContainer}> 
     <Text> Testing the Router </Text> 
     </View> 
    ) 
    } 
}; 

module.exports = Main; 
+0

你能顯示你的'Main'組件代碼嗎? –

+0

它現在在那裏。 – user1072337

回答

1

啊,它看起來像initialRoute應該是一個對象,但是你把它裹在括號:

現在如何,它是:

initialRoute={(
    title: 'Thingy', 
    component: Main 
)} 

實際上應該是:

initialRoute={{ 
    title: 'Thingy', 
    component: Main 
}} 
+0

這是ES6的新語法嗎? – user1072337

+0

實際上,現在它說它找不到主... – user1072337

+1

我不得不要求它,沒關係。 – user1072337