[React-Native]RN数据管理

2016-08-19  本文已影响63人  美乃滋酱啊

Component

可以在Component的Constructor中设置成员变量

// 构造
constructor(props) {
    super(props);
    // 初始状态
    this.state = {
        switchOn: false,
        selectedLanguage: 'java',
        ...
        key:value
    };
}

render()中的各个组件中的属性中,可以使用

this.state.key

获得该key的值,可以使用

this.setState({key:value});

设置属性值。

props

你可以使用

<Demos navigator={navigator}/>

把相关的数据传到Demos这个视图中,然后在Demos中获取到navigator这个属性

<TouchableWithoutFeedback 
  onPress={()=>{
                  this.props.navigator.push({index:3});
                       }
                    }>
上一篇 下一篇

猜你喜欢

热点阅读