undefined is not an object (evaluating 'this.props.navigator.push')新手求大神解救 卡了好几天了



  • 0_1499832937355_屏幕快照 2017-07-12 12.14.19.png
    这个是项目目录结构0_1499832960863_屏幕快照 2017-07-12 12.14.43.png
    报错问题
    /**

    import React, { Component } from 'react';
    import {
    AppRegistry,
    StyleSheet,
    Text,
    View,
    ListView,
    Image,
    TouchableOpacity,
    Navigator
    } from 'react-native';
    var Listpage = require('../Home/listpage');
    var Dimensions = require('Dimensions');
    var {width ,height} = Dimensions.get('window');
    var boxW = 140;
    var boxH =100;
    var cols = 20;
    var URL_addrss="http://192.168.10.101:8080/YZsoft/xiniu.json";
    var xiniuhome=React.createClass( {
    //初始化方法
    getInitialState(){
    return{
    // cell 数据源
    dataSource:new ListView.DataSource({rowHasChanged:(r1,r2)=>r1!==r2 })
    }
    },
    render() {
    return (
    <ListView
    dataSource={this.state.dataSource}
    renderRow={this.renderRow}
    />
    );
    },
    renderRow(rowData){
    return(
    <TouchableOpacity activeOpacity={0.7} onPress={this.pushTolistpage}>
    <View >
    <View style={styles.viewstyle}>
    <View style={styles.leftImageview}>
    <Image source={{uri:rowData.mainPic}} style={styles.Imageviewstyle}/>
    </View>
    <View style={styles.rightTopview}>
    <View>
    <Text style={styles.buildingnamestyle}>{rowData.propertyName}</Text>
    <View style={styles.addressstyle}>
    <Text style={styles.citynamestyle}>{rowData.cityName}{rowData.boroughName}</Text>
    <Text style={styles.averagePricestyle}>{rowData.averagePrice}/㎡</Text>
    </View>
    <View style={styles.addressstyle}>
    <Text style={styles.acveragestyle}>{rowData.minAcreage}{rowData.maxAcreage}/㎡</Text>

                      </View>
                      <View style={styles.addressstyle}>
    
                          <Text style={styles.acveragestyle}>{rowData.buildingType}</Text>
                          <Text style={styles.acveragestyle}>{rowData.buildingTypechange}</Text>
    
                      </View>
                  </View>
              </View>
          </View>
              <View style={styles.linestyle}></View>
    
          </View>
          </TouchableOpacity>
      )
    },
    //页面跳转
    

    pushTolistpage(rowData){
    this.props.navigator.push({
    component: Listpage,
    title: '{rowData.boroughName}',
    rightButtonTitle: 'Shopping',
    });
    },
    // 请求网络数据
    componentDidMount(){
    this.loadnetwork();

    },
    loadnetwork(){
        fetch(URL_addrss)
          .then((response)=>response.json())
            .then((responseData)=>{
                this.setState({
                    dataSource: this.state.dataSource.cloneWithRows(responseData.projectInf),
    
                });
    
        }).catch((error) => {
            console.error(error);
        });
    }
    

    })

    const styles = StyleSheet.create({
    viewstyle: {
    flexDirection:'row',
    width:width-cols*2,
    marginLeft:cols,
    marginRight:cols,

    },
    leftImageview:{
      flexDirection:'row'
    },
    Imageviewstyle:{
        width:boxW,
        height:boxH,
        borderRadius:8,
    },
    linestyle:{
        width:width-cols*2,
        height:1,
        marginLeft:cols,
        marginRight:cols,
        marginTop:10,
        marginBottom:10,
        borderWidth:1,
        borderColor:'#f5f5f5'
    },
    addressstyle:{
        flexDirection:"row",
        marginTop:5,
    },
    rightTopview:{
        marginLeft:10,
    },
    buildingnamestyle:{
        color:"#333333",
        fontSize:16,
        fontWeight:'bold'
    
    },
    citynamestyle:{
        fontSize:14,
        color:"#333333",
        marginRight:30,
    },
    averagePricestyle:{
        fontSize:14,
        textAlign:"right"
    },
    acveragestyle:{
        backgroundColor: '#f5f5f5',
        marginRight:5,
        color:"#999999",
        padding:5,
    },
    

    });

    module.exports=xiniuhome;



  • 你这个页面是在哪儿引用的?
    要不在你引用这个页面组件那加上这句navigator={this.props.navigator}或{...this.props}试试...



  • 建议你类比下http://bbs.reactnative.cn/topic/4145/%E5%85%B3%E4%BA%8Enavigator%E9%A1%B5%E9%9D%A2%E8%B7%B3%E8%BD%AC%E7%9A%84%E9%97%AE%E9%A2%98/2


登录后回复