2016-04-26 83 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>} 
/>