Javascript React Native:如何将组件中的项与另一个组件中的项绑定?

Javascript React Native:如何将组件中的项与另一个组件中的项绑定?,javascript,reactjs,react-native,bind,react-navigation,Javascript,Reactjs,React Native,Bind,React Navigation,我正在尝试使用创建日历。 例如,当我在日历组件中单击2018年12月5日时,它应该在议程组件中导航到2018年12月5日。这就是我想做的 这是我的Calendar Component代码,我正在尝试获取id并将其绑定: class Calendar extends Component { constructor(props) { super(props); this.state = { active: 'true'

我正在尝试使用创建日历。 例如,当我在
日历组件中单击2018年12月5日时,它应该在
议程组件中导航到2018年12月5日。这就是我想做的

这是我的
Calendar Component
代码,我正在尝试获取id并将其绑定:

    class Calendar extends Component {
    constructor(props) {
        super(props);
         this.state = {
             active: 'true'
         }
    }

    render() { 
        const {onSelect} = this.props;
        return ( 
            <View>
                <CalendarList 
                    keyExtractor = {day=>day.id}
                    onDayPress={(day) => {onSelect.bind(this, day)}}
                    pastScrollRange={12}
                    futureScrollRange={12}
                    scrollEnabled={true}
                    showScrollIndicator={true}
                />
            </View>
         );
    }
}

Calendar.propTypes = {
    onSelect: PropTypes.func,
}
我还提到了解决办法。但是没有运气

编辑:

这是我的
议程组件

    class WeeklyAgenda extends Component {
    constructor(props) {
    super(props);
    this.state = {
      items: {}
    };
  }

  render() {
    return (
        <View style={{height:600}}>
             <Agenda
                items={this.state.items}
                loadItemsForMonth={this.loadItems.bind(this)}
                selected={Date()}
                renderItem={this.renderItem.bind(this)}
                renderEmptyDate={this.renderEmptyDate.bind(this)}
                rowHasChanged={this.rowHasChanged.bind(this)}
                onRefresh = {() => { this.setState({refeshing : true})}}
                refreshing = {this.state.refreshing}
                refreshControl = {null}
                pastScrollRange={1}
                futureScrollRange = {3}
            />
    );
  }

日历通过CalenderScreen在Select(id)上进行回调

日历屏幕只需要调用onSelect(天)

或者让回调同时接受导航对象和日期

onDayPress={(day) => {onSelect(day, navigation)}}
日历现在应该设置好了

onSelect={(day, navigation)=>{
        navigation.navigate('Agenda', {day}) }}>
或者,当您将导航对象传递给日历时,为什么要传递回调

onDayPress={(day) => {this.props.navigation.navigate('Agenda', {day})}}
编辑:新建类,并将id更改为day

同样的问题。onSelect导航到AgentScreen并将导航道具(其中包含day对象)传递给它,然后AgentScreen将导航道具传递给WeeklyAgent,但WeeklyAgent不使用导航道具获取id

selected={Date()}
创建具有今天日期的新日期对象。 要获得正确的日期,您需要从导航中获得日期,通常是沿着

this.props.navigation.state.params["day"]
返回通过的日期

现在,如果WeeklyAgenda不进一步使用导航,我不会通过它

相反,每周议程应该有一个道具“日”,因此

 <WeeklyAgenda  navigation={navigation}>
我认为这里的问题根本不在于装订。
我建议您阅读这篇或那篇关于绑定功能的文章。

您是否收到错误消息?@RachelGallen不,没有错误。谢谢您的回复。使用这两种方法中的任何一种,我都可以从
CalendarScreen
导航到
AgendarScreen
,但我不能说,从
CalendarScreen
的12月20日导航到
AgendarScreen的12月20日。
它确实导航,但只带我到当前日期。不看AgendarScreen,很难说为什么。你确定你度过了正确的一天吗?在AgendaScreen中,从导航打印id。AgendaScreen是否使用id设置日期?很抱歉,我是一个地道的初学者。我已使用
议程组件
代理屏幕
更新了我的描述。我显然漏掉了一些东西,但不确定
WeeklyAgenda
到底是如何进一步使用导航的。它导航到带有所选日期的提醒页面。您可以通过回调代替,如onDayPress
selected={Date()}
this.props.navigation.state.params["day"]
 <WeeklyAgenda  navigation={navigation}>
const { params } = this.props.navigation.state;
...
<WeeklyAgenda  day={params["day"}>
selected={this.props.day}