2016-04-26 82 views
0

我想填充在我的使用從火力地堡數據作出反應,本機應用程序列表視圖,我目前正在此錯誤:clonewithrows陣列問題反應母語

「的對象是不是一個做出反應的孩子有效(找到對象如果你打算渲染一個孩子的集合,改爲使用一個數組或者使用React插件中的createFragment(object)來包裝對象,檢查'Text'的渲染方法。「

This發生在我打電話給clonewithrows的時候。目前我對該功能的輸入(解析Firebase響應之後)是:[{title:'New York'},{title:'Boston'}]

這是我的相關代碼;如果您發現任何可能導致問題的信息,請告訴我。

const huntsRef = new Firebase(`${ config.FIREBASE_ROOT }/hunts`) 


class Home extends Component { 
    constructor(props) { 
     super(props); 
     var conDataSource = new ListView.DataSource(
      {rowHasChanged: (r1, r2) => r1.guid != r2.guid}); 

     this.state = { 
      dataSource: conDataSource 
     }; 
    } 

    listenForItems(huntsRef) { 

     huntsRef.on('value', (snap) => { 
      var hunts = []; 
      snap.forEach((child) => { 
       hunts.push({ 
        title: child.val().title 
       }); 
      }); 

      this.setState({ 
       dataSource: this.state.dataSource.cloneWithRows(hunts) 
      }); 
      console.log('datasource' + this.state.dataSource); 
     }); 
    } 

    componentDidMount() { 
     this.listenForItems(huntsRef); 
    } 

    renderRow(rowData, sectionID, rowID) { 
     console.log("ROWDATA" + rowData); 
    } 

    render() { 

     return (
     <ListView 
      dataSource={this.state.dataSource} 
      renderRow={(rowData) => <Text>{rowData}</Text>} 
     /> 
    ); 
    } 
} 

module.exports = Home; 

回答

1

如消息所示,rowData是JavaScript對象,無法呈現。你可以將你的rowData串聯起來。例如:

<ListView 
    dataSource={this.state.dataSource} 
    renderRow={(rowData) => <Text>{JSON.stringify(rowData)}</Text>} 
/>