undefined 不是一个对象(评估'this.props.navigator.push') [英] undefined is not an object (evaluating 'this.props.navigator.push')

查看:29
本文介绍了undefined 不是一个对象(评估'this.props.navigator.push')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法完成这项工作,已交叉检查所有参考资料,但无济于事.这是视图的所有代码.

Can't make this work, have cross checked all the references, but it isn't helping. Here is all the code for the view.

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

I am not sure what I am missing, have required all the dependencies.

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;

推荐答案

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

If you're calling your ListView component like this, it should work. NavigatorIOS already passes the reference down (but just one level/generation).

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

但是如果您从 NavigatorIOS 引用的组件的子组件中调用 ListView 组件,请尝试此操作.从 NavigatorIOS 引用的组件中,您在其中调用 添加一个导航器属性.

But if you're calling your ListView component from within a child component of the component referenced by NavigatorIOS, try this. From the component referenced by NavigatorIOS, where you call <ListView /> add a navigator property.

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

您需要记住在子组件中传递您要访问的属性,因此如果您想将 <NavigatorIOS/> 中显示的组件从 NavigatorIOS 未直接引用的组件中更改那么你需要像上面一样传递 navigator 属性.

You need to remember to pass the properties you want to access in the child components so if you want to change the component displayed in <NavigatorIOS /> from a component not directly referenced by NavigatorIOS then you need to pass the navigator property down like above.

希望这会有所帮助.

这篇关于undefined 不是一个对象(评估'this.props.navigator.push')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆