React Native Navigator意外令牌

时间:2016-08-12 10:35:39

标签: android react-native

我正在尝试在场景之间切换并测试<{Some imported Scene} />完美无缺,但以下代码没有。 我是React-Native的新手,我得到的错误是index.android.js第30行的意外令牌,这就是说this.(scene[route.name] || scene['LoginView']);

的行
  

index.android.js

import React, { Component } from 'react'
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  TextInput,
  Navigator,
  TouchableHighlight
} from 'react-native';

import LoginView from './Scence-Android/LoginView';
import SettingView from './Scence-Android/SettingView';

class TrackrModule extends Component {
  render() {
    return (
      <View>
        <Navigator
          initialRoute={{ name: 'LoginView' }}
          renderScene={ (route, navigator) => {
            var scene = {
              "LoginView": () => {
                return (<LoginView navigator={navigator} title="Login" />)
              },
              "SettingView": () => {
                return (<SettingView navigator={navigator} title="Setting" />)
              }
            }
            this.(scene[route.name] || scene['LoginView']);
          }}
        />
      </View>
    );
  }
}
  

LoginView

import React, {Component} from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  TextInput,
  Navigator,
  TouchableHighlight
} from 'react-native';

export default class LoginView extends Component {
  constructor(props){
    super(props);
    this.state = {
      username: "",
      password: ""
    };
  }
  btnLogin_pressed(){
    this.props.navigator.push({
      name:"SettingView"
    });
  }

  render(){
    return (
      <View style={styles.container}>
        <View style={styles.loginContainer}>
          <TextInput>
            placeholder="Username"
            style={styles.textInput}
            onChange={(event) => this.setState({username: event.nativeEvent.text})}
            value={this.state.username}
          </TextInput>

          <TextInput>
            placeholder="Password"
            secureTextEntry = { true }
            style={styles.textInput}
            onChange={(event) => this.setState({password: event.nativeEvent.text})}
            value={this.state.password}/>
          </TextInput>

          <TouchableHighlight onPress={this.btnLogin_pressed.bind(this)}>
            <Text>Login</Text>
          </TouchableHighlight>
        </View>
      </View>
    )
  }
}

1 个答案:

答案 0 :(得分:1)

在javascript之后你不能成为a()运算符。因此List<ClsOrder> ordlist会给您一个错误。

您还需要从renderScene方法返回一个组件。因此,以下代码比this.(scene[route.name] || scene['LoginView']);更合适:

this.(scene[route.name] || scene['LoginView']);