2016-09-15 78 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