2016-06-17 7 views
0

私を助けてください。同じカテゴリの画面間を移動しますが、動作しません。自分のコードを添付しました。未定義の未解決のネイティブログはオブジェクトではありません(評価 '_this.props.passProps.exmpale')

Sickness.php

mysql_connect('localhost','root',''); 
    mysql_select_db('sucKhoe'); 
    mysql_query('SET NAMES utf8'); 


    $data = json_decode(file_get_contents('php://input'), true); 

    $arrSickness = array(); 
    $categoryId= $data["categoryId"]; 
    class sickness{ 
    var $sickName; 

    function sickness($_name){ 
     $this->sickName = $_name; 

    } 
    } 

    $sql = "SELECT * FROM Sickness WHERE CategoryId = " .$categoryId ; 
    $query = mysql_query($sql); 

    while($row = mysql_fetch_array($query)){ 
    array_push($arrSickness, new sickness($row["SickName"])); 
    } 

    echo json_encode($arrSickness); 

Category.js

import React, {Component} from 'react'; 
    import { 
     Text, 
     View, StyleSheet, ListView, StatusBar, TouchableOpacity 
    } from 'react-native'; 

var deviceScreen = require('Dimensions').get('window') 

var URL_API = 'http://localhost/Cancer_API/Category.php' 
var URL = 'http://localhost/Cancer_API/Sickness.php' 

class Category extends Component{ 


    constructor(props){ 
    super(props); 
    this.state = { 
     dataSource: new ListView.DataSource({rowHasChanged:(r1,r2) => r1 !== r2}) 
    }; 
    this.pushView = this.pushView.bind(this); 
    } 

    fetchData(){ 
    fetch(URL_API, {method: "POST", body: null}) 
     .then((response) => response.json()) 
     .then((responseData) => { 
     this.setState({ 
      dataSource: this.state.dataSource.cloneWithRows(responseData) 
     }) 
     }) 
     .done() 
    } 

    componentDidMount(){ 
    this.fetchData(); 
    } 

    taoHang(property){ 
     return(
     <TouchableOpacity style={styles.hang} 
      onPress={()=> this.pushView(property.categoryId, property.categoryName)}> 
      <View style={styles.viewName}> 
      <Text style={styles.name}>{property.categoryName}</Text> 
      </View> 
     </TouchableOpacity> 
    ); 
    } 

    pushView(id, name){ 
    fetch(URL, {method: "POST", body: JSON.stringify({categoryId: id})}) 
     .then((response) => response.json()) 
     .then((responseData) => { 
     this.props.navigator.push({ 
      name:'Sickness', 
      component: require('./Sickness'), 
      props: {title: name, sickness: responseData} 
     }); 
     }) 
     .done() 
    } 

    render(){ 
    return(
     <View style={styles.container}> 
     <View style={styles.header}> 
      <TouchableOpacity style={styles.backButton} 
      onPress={()=> this.props.navigator.pop()} > 
      <Text style={styles.backHeader}>Back</Text> 
      </TouchableOpacity> 
      <View style={styles.baoTitle}> 
      <Text style={styles.titleHeader}>Tin Tuc</Text> 
      </View> 
     </View> 
     <View style={styles.danhsach}> 
      <ListView dataSource={this.state.dataSource} 
      renderRow={this.taoHang.bind(this)} /> 
     </View> 
     </View> 

    ); 
    } 
} 

var styles = StyleSheet.create({ 
    container:{ 
    flex: 1, 
    }, 
    header:{ 
    flexDirection:'row', 
    flex: 1, 
    backgroundColor:'#09C' 
    }, 
    backButton:{ 
    flex: 1, 
    justifyContent:'center', 
    alignItems:'center', 
    backgroundColor:'#09C' 
    }, 
    baoTitle:{ 
    flex: 6, 
    justifyContent:'center', 
    alignItems:'center', 
    marginRight: deviceScreen.width/7 , 
    backgroundColor:'#09C' 
    }, 
    titleHeader:{ 
    color:'white', 
    fontSize:20, 
    fontWeight:'400' 
    }, 
    backHeader:{ 
    color:'white', 
    fontSize:16, 
    fontWeight:'400' 
    }, 
    danhsach:{ 
    flex: 10, 
    backgroundColor: '#F7F7F7' 
    }, 
    hang:{ 
    flexDirection: 'row', 
    flex: 1, 
    padding: 10, 
    borderBottomWidth: 1, 
    borderColor: '#09C' 
    }, 
    viewName:{ 
    flex: 1, 
    justifyContent:'center', 
    alignItems:'center', 
    }, 
    name:{ 
    fontSize: 18, 
    fontWeight: '300' 
    } 
}) 

module.exports = Category; 

Sickness.js

import React, {Component} from 'react'; 
import { 
    Text, 
    View, StyleSheet, ListView, StatusBar, TouchableOpacity 
} from 'react-native'; 

var deviceScreen = require('Dimensions').get('window') 
var URL = 'http://localhost/Cancer_API/Sickness.php' 

class Sickness extends Component{ 


    constructor(props){ 
    super(props); 
    var ds = new ListView.DataSource({rowHasChanged:(r1,r2) => r1 !== r2}) 
    this.state = { 
     dataSource: ds.cloneWithRows(this.props.passProps.sickness) 
    }; 
    this.pushView = this.pushView.bind(this); 
    } 

    taoHang(property){ 
    return(
     <TouchableOpacity style={styles.hang} 
     onPress={()=> this.pushView()}> 
     <View style={styles.viewName}> 
      <Text style={styles.name}>{property.sickName}</Text> 
     </View> 
     </TouchableOpacity> 
    ); 
    } 

    pushView(id, name){ 
    fetch(URL, {method: "POST", body: JSON.stringify({categoryId: id})}) 
     .then((response) => response.json()) 
     .then((responseData) => { 
     this.props.navigator.push({ 
      name:'Sickness', 
      component: require('./Sickness'), 
      props: {title: name, sickness: responseData} 
     }); 
     }) 
     .done() 
    } 

    render(){ 
    return(
     <View style={styles.container}> 
     <View style={styles.header}> 
      <TouchableOpacity style={styles.backButton} 
      onPress={()=> this.props.navigator.pop()} > 
      <Text style={styles.backHeader}>Back</Text> 
      </TouchableOpacity> 
      <View style={styles.baoTitle}> 
      <Text style={styles.titleHeader}>Tin Tuc</Text> 
      </View> 
     </View> 
     <View style={styles.danhsach}> 
      <ListView dataSource={this.state.dataSource} 
      renderRow={this.taoHang.bind(this)} /> 
     </View> 
     </View> 

    ); 
    } 
} 

var styles = StyleSheet.create({ 
    container:{ 
    flex: 1, 
    }, 
    header:{ 
    flexDirection:'row', 
    flex: 1, 
    backgroundColor:'#09C' 
    }, 
    backButton:{ 
    flex: 1, 
    justifyContent:'center', 
    alignItems:'center', 
    backgroundColor:'#09C' 
    }, 
    baoTitle:{ 
    flex: 6, 
    justifyContent:'center', 
    alignItems:'center', 
    marginRight: deviceScreen.width/7 , 
    backgroundColor:'#09C' 
    }, 
    titleHeader:{ 
    color:'white', 
    fontSize:20, 
    fontWeight:'400' 
    }, 
    backHeader:{ 
    color:'white', 
    fontSize:16, 
    fontWeight:'400' 
    }, 
    danhsach:{ 
    flex: 10, 
    backgroundColor: '#F7F7F7' 
    }, 
    hang:{ 
    flexDirection: 'row', 
    flex: 1, 
    padding: 10, 
    borderBottomWidth: 1, 
    borderColor: '#09C' 
    }, 
    viewName:{ 
    flex: 1, 
    justifyContent:'center', 
    alignItems:'center', 
    }, 
    name:{ 
    fontSize: 18, 
    fontWeight: '300' 
    } 
}) 

module.exports = Sickness; 

enter image description here

iOSシミュレータログは未定義でOBJECではありませんトンpassPropsにCategory.js変更小道具で

+0

あなたの** sickness.js **ファイルには: 'this.props.navigator.push({name: 'Sickness'、コンポーネント:require( './ Sickness'、passProps:{title:name 、sickness:responseData}}); ' –

+0

私はそれを削除しましたが、このエラーはまだ発生します – phuochq

答えて

0

を( '_this.props.passProps.sickness' を評価):Sickness.jsで

this.props.navigator.push({ 
    name:'Sickness', 
    component: require('./Sickness'), 
    passProps: {title: name, sickness: responseData} 
}); 

あなたは、単に小道具としてpassPropsを得る:

this.state = { 
    dataSource: ds.cloneWithRows(this.props.sickness) 
}; 
関連する問題