【问题标题】:undefined is not an object (evaluating 'this.props.navigator.push')undefined 不是对象(评估“this.props.navigator.push”)
【发布时间】:2015-07-16 18:16:12
【问题描述】:

无法完成这项工作,交叉检查了所有参考资料,但没有帮助。这是视图的所有代码。

我不确定我缺少什么,需要所有依赖项。

var React = require('react-native');
var Delivery = require('./Delivery');

var {
    View,
    Text,
    StyleSheet,
    TouchableHighlight,
} = React;


class ListItem extends React.Component{

    showDetails(){
        this.props.navigator.push({
            title: "Delivery details",
            component: Delivery
        });
    }

    render(){
        return(
            <TouchableHighlight onPress={this.showDetails.bind(this)} >
                <View style={styles.listItem}>
                    <View style={styles.listContents}>
                        <Text style={styles.listHead}>JMD Megapolis</Text>
                        <Text style={styles.listAddress}>1109, Sector 48, Sohna Road, Gurgaon 122018</Text>
                        <Text style={styles.listMeta}>2Kms from store</Text>
                    </View>
                    <View style={styles.listCost}>
                        <Text style={styles.cost}>₹40</Text>
                    </View>
                </View>
            </TouchableHighlight>
        )
    }
}

module.exports = ListItem;

【问题讨论】:

  • 将数据分配给组件的代码在哪里?
  • 暂时都是静态数据,没有动态。
  • 他问的是你在哪里初始化ListItem?在某个地方你应该有类似
  • 上个月有人遇到了同样的问题,并在github上提到过。阅读本文,您将找到解决方案:github.com/facebook/react-native/issues/416。底线...您在哪里添加 NavigatorIOS?
  • 点击here,希望对你有帮助!

标签: reactjs react-native


【解决方案1】:

如果您像这样调用 ListView 组件,它应该可以工作。 NavigatorIOS 已经将引用向下传递(但只有一级/代)。

<NavigatorIOS
    initialRoute={{
        title: 'List View Component',
        component: ListView,
    }} />

但是,如果您从 NavigatorIOS 引用的组件的子组件中调用 ListView 组件,请尝试此操作。在 NavigatorIOS 引用的组件中,您调用 &lt;ListView /&gt; 添加一个 navigator 属性。

<ListView navigator={this.props.navigator} />

您需要记住在子组件中传递要访问的属性,因此如果您想从 NavigatorIOS 未直接引用的组件更改 &lt;NavigatorIOS /&gt; 中显示的组件,那么您需要将 navigator 属性向下传递,例如以上。

希望这会有所帮助。

【讨论】:

  • *** navigator={this.props.navigator} *** OMG TY!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-16
  • 2018-08-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多