Javascript 在不使用导航器的情况下反应本机传球道具?

Javascript 在不使用导航器的情况下反应本机传球道具?,javascript,ios,reactjs,react-native,Javascript,Ios,Reactjs,React Native,我想知道是否可以在不使用导航器的情况下传递属性?我试图做的是将道具传递给位于index.ios.js中的webview 本质上,我的index.ios.js中有一个不可见的iframe,它允许在整个应用程序中播放歌曲,尽管视图发生了变化,但我需要在按下按钮时更新WebView的源代码 我的index.ios.js如下所示: class queueThat extends React.Component { constructor(props) { super(props);

我想知道是否可以在不使用导航器的情况下传递属性?我试图做的是将道具传递给位于index.ios.js中的webview

本质上,我的index.ios.js中有一个不可见的iframe,它允许在整个应用程序中播放歌曲,尽管视图发生了变化,但我需要在按下按钮时更新WebView的源代码

我的index.ios.js如下所示:

class queueThat extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      source: ''
    };
  }



  render() {
    return (
      <View style={styles.container}>
      <View style={styles.iframe}>
        <WebView html={this.props.source} />
      </View>
      <React.NavigatorIOS
        style={styles.container}
        initialRoute={{
          title: 'queueThat',
          component: SearchPage, 
        }}/>
        </View>

    );
  }
}
扩展React.Component的类队列{
建造师(道具){
超级(道具);
此.state={
来源:“”
};
}
render(){
返回(
);
}
}
“我的搜索结果”页面按功能如下所示:

  rowPressed(rowID) {
    this.setState({source: '<iframe width="100%" height="0" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/' + this.props.collection[rowID].id + '&amp;auto_play=true&amp;hide_related=false&amp;show_comments=true&amp;show_user=true&amp;show_reposts=false&amp;visual=true"></iframe>'})
    console.log(this.state.source)
    this.props.navigator.push({
      passProps: {source: this.state.source}
    })
  }
rowPressed(rowID){
this.setState({source:'})
console.log(this.state.source)
这个是.props.navigator.push({
passProps:{source:this.state.source}
})
}
我正在尝试将源代码传递到位于我的index.ios.js中的WebView html,而不离开当前视图。

PS-我对JS和React非常陌生。

您可以通过在该类中创建set方法并将其传递给另一个组件来实现这一点

index.ios.js

class queueThat extends React.Component {

  ...

  // Your setSource method to update state from other component
  setSource = (source) => {
    this.setState({source: source});
  };

  render() {
    return (

      ...

      <React.NavigatorIOS
        style={styles.container}
        initialRoute={{
          title: 'queueThat',
          component: SearchPage, 
          passProps: { setSource: this.setSource }
        }}/>

      ...

    );
  }
}

您可以通过在该类中创建set方法并将其传递给另一个组件来实现这一点

index.ios.js

class queueThat extends React.Component {

  ...

  // Your setSource method to update state from other component
  setSource = (source) => {
    this.setState({source: source});
  };

  render() {
    return (

      ...

      <React.NavigatorIOS
        style={styles.container}
        initialRoute={{
          title: 'queueThat',
          component: SearchPage, 
          passProps: { setSource: this.setSource }
        }}/>

      ...

    );
  }
}