2016-07-21 69 views
1

我正在訪問數據庫中的數據,我想在ListView中顯示它。 我正在以下列方式執行此操作。datasource.rowIdentifier是反應原生的未定義錯誤

const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}); 

const LoadingPage=()=>(
    <View style={{backgroundColor:"blue"}}> 
    <Image style={{width:150, height:100,bottom:60}} source={require('./drawable/drawable/asap.png')}/> 

    </View> 
) 
const Row = (props) => (
    <View style={styles.container}> 
    <Text style={styles.text}> 
     {`${props.paymentType.name} ${props.amount} ${props.date} ${props.description}`} 
    </Text> 
    </View> 
); 

async fetchData(){ 
    var DEMO_TOKEN = await AsyncStorage.getItem(STORAGE_KEY); 

    fetch(" http://asaptest-sas71.rhcloud.com/api/approvals", { 
     method: 'get', 
     dataType: 'json', 
     headers: { 
      'Accept': 'application/json', 
      'Content-Type': 'application/json', 
      'Authorization': DEMO_TOKEN 
     }, 
     }).then((response) => 
     { 
      return response.json() // << This is the problem 
     }).then(function(data) { 
      console.log(data); 
      const tempNames = [];  

      for(var i=0;i<data.length;i++){ 
       tempNames.push(data[i]); 
      } 
      this.setState({ approvals: tempNames,dataSource: ds.cloneWithRows(this.state.approvals)}); 
      alert(JSON.stringify(this.state.approvals,null,4)) 



      }.bind(this)).catch(function(err) { 
      //alert("Error is"+err) 

      console.log(err); 
     }) 
     .done(); 

} 
componentDidMount(){ 
    this.fetchData(); 
    setTimeout(this.setTimePassed() 
      , 2000) ; 
} 
setTimePassed() { 
this.setState({timePassed: true}); 
} 
render(){ 
    if (!this.state.timePassed){ 
    return <LoadingPage/> 
    } 
    else{ 
    return (

     <ListView 
     dataSource={this.state.dataSource} 
    />) 
    } 
} 

但它給錯誤,undefined是不是(評估「dataSource.rowidentifiers」) 請幫我解決這個問題的對象。

回答

相關問題