React native 在React Native中处于未打印状态

React native 在React Native中处于未打印状态,react-native,state,React Native,State,我现在正在使用React Native。现在,我试图打印一个已初始化的状态(例如,这里的showText)。当我在render中调用此值时,它不会显示(空白)。我记得的方式是“{this.state.showText}”。它不会产生任何错误消息 可能是因为同样的原因,TouchableHighlight的初始值似乎为空。我完全迷失在这里,因为Facebook Github中的一个示例应用程序在网站中运行良好。请告诉我关于这件事的任何想法 import React, { Component } f

我现在正在使用React Native。现在,我试图打印一个已初始化的状态(例如,这里的showText)。当我在render中调用此值时,它不会显示(空白)。我记得的方式是“{this.state.showText}”。它不会产生任何错误消息

可能是因为同样的原因,TouchableHighlight的初始值似乎为空。我完全迷失在这里,因为Facebook Github中的一个示例应用程序在网站中运行良好。请告诉我关于这件事的任何想法

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


class Greeting extends Component {
  render() {
    return (
      <Text>Hello {this.props.name}! {this.props.date}~ Class can be added..{'\n'}</Text>
    );
  }
} 
class Test1 extends Component {

  constructor(props) {
    super(props);
    this.state = {
      showText: 'true',
      showTextBool: true,
      wow: 'ddsdfasdf'
    };

  }

  onSignupPress(){
    return "hello";
  }

  render() {

    let display = this.state.showTextBool ? 'true' : 'false';

    return (

      <View style={styles.container}>
        <Text style={styles.welcome}>
          Welcome to React Native! {this.state.showText} {this.state.showTextBool}
          {this.state.wow}
        </Text>


        <TextInput style={styles.searchInput} value={this.state.wow} placeholder='Search via name or postcode'/>


        <TouchableHighlight style={styles.button} underlayColor='#99d9f4'>
          <Text style={styles.buttonText}>Go</Text>
        </TouchableHighlight>


        <Text style={styles.welcome}>
          {display} + {this.onSignupPress()} + {this.state.showText}
        </Text>

      </View>

    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },

  buttonText: {
    color: 'white',
    alignSelf: 'center'
  },

  button: {
    height: 36,
    flex: 1,
    flexDirection: 'row', 
    backgroundColor: '#48BBEC', 
    borderColor: '#48BBEC', 
    borderWidth: 1, 
    borderRadius: 8, 
    marginBottom: 10, 
    alignSelf: 'stretch', 
    justifyContent: 'center'
  },

  searchInput: {
    height: 36,
    padding: 4, marginRight: 5,
    flex: 4,
    fontSize: 18, borderWidth: 1, borderColor: '#48BBEC', borderRadius: 8, color: '#48BBEC'
  }

});

AppRegistry.registerComponent('Test1', () => Test1);
import React,{Component}来自'React';
进口{
评估学,
样式表,
文本,
看法
形象,,
滚动视图,
ListView,
触控高光,
文本输入框
}从“反应本机”;
类扩展组件{
render(){
返回(
你好{this.props.name}!{this.props.date}~可以添加类..{'\n'}
);
}
} 
类Test1扩展了组件{
建造师(道具){
超级(道具);
此.state={
showText:'true',
showTextBool:是的,
哇:'ddsdfasdf'
};
}
onSignupPress(){
回复“你好”;
}
render(){
let display=this.state.showTextBool?'true':'false';
返回(
欢迎使用React Native!{this.state.showText}{this.state.showTextBool}
{这个州,哇}
去
{display}+{this.onSignupPress()}+{this.state.showText}
);
}
}
const styles=StyleSheet.create({
容器:{
弹性:1,
为内容辩护:“中心”,
对齐项目:“居中”,
背景颜色:“#F5FCFF”,
},
欢迎:{
尺寸:20,
textAlign:'中心',
差额:10,
},
说明:{
textAlign:'中心',
颜色:'#333333',
marginBottom:5,
},
按钮文字:{
颜色:'白色',
自我定位:“中心”
},
按钮:{
身高:36,
弹性:1,
flexDirection:'行',
背景颜色:“#48BBEC”,
边框颜色:“#48BBEC”,
边框宽度:1,
边界半径:8,
marginBottom:10,
自我定位:“拉伸”,
为内容辩护:“中心”
},
搜索输入:{
身高:36,
填充:4,边缘:5,
弹性:4,
fontSize:18,borderWidth:1,borderColor:'#48BBEC',borderRadius:8,color:'#48BBEC'
}
});
AppRegistry.registerComponent('Test1',()=>Test1);

我在react native express页面中尝试了您的代码。它会呈现一个“true”,但您需要两个(文本和布尔值)。在以下部分:

Welcome to React Native! {this.state.showText} {this.state.showTextBool}
文本被正确地呈现(它说的确实是“true”),但是布尔值不存在,主要是因为您无法呈现这样的布尔值。尝试以下方法:

{String(this.state.showTextBool)}

这将正确呈现布尔值。

我在react native express页面中尝试了您的代码。它会呈现一个“true”,但您需要两个(文本和布尔值)。在以下部分:

Welcome to React Native! {this.state.showText} {this.state.showTextBool}
文本被正确地呈现(它说的确实是“true”),但是布尔值不存在,主要是因为您无法呈现这样的布尔值。尝试以下方法:

{String(this.state.showTextBool)}
这将正确呈现布尔值