子控件中在相应的函数中。通过props.coallback的回调通知父组件。

父组件调用callback属性时行 绑定,并在方法中去解析使用获取到的值 。

//子控件:
<TouchableHighlight onPress={this._onPressButton.bind(this)}>
_onPressButton(){
this.props.callback("hello wrold");
}

//父控件
<View style={{alignItems: 'center'}} callback={this._onPressButton.bind(this)}>
_onPressButton(str){
str....
}

父组件向子组件传递数据

通过ref属性实现
父组件直接通过ref的属性找到相应的子组件,调用相对应的方法。

<AssetList ref='myRef' dtList={this.state.data[this.state.index]}/>

this.refs.myRef.setState(
{
data:this.state.data[this.state.index]
}

)

本文由 hcb 创作,采用 知识共享署名 3.0,可自由转载、引用,但需署名作者且注明文章出处。

还不快抢沙发

添加新评论