cloneWithRows can't work with array
Hi ,
I want to put data from Parse in listview. I try this:
constructor(props) { super(props); const dataSource = new ListView.DataSource({ rowHasChanged: (row1, row2) => row1 !== row2, }); this.state = { dataSource: dataSource, } }
then , i create those 3 functions:
**Function renderItem :
_renderItem(task) { return ( <ListItem task={task} /> ); }
**Function listenForTasks:
listenForTasks( ) { Parse.initialize("APPID"); Parse.serverURL = 'URL'; var GameScore = Parse.Object.extend("Category"); var gameScore = new GameScore(); var tasks = []; var ds = this.state.dataSource; var query = new Parse.Query(gameScore); query.find({ success: function(results) { for (var i = 0; i < results.length; i++) { tasks.push({ name: results[i].get("name"), _key: results[i].get("objectId") }); } this.setState({ dataSource: ds.cloneWithRows(tasks.slice()) }); }, error: function(error) { alert( mystate ); }, })
**Function componentDidMount
componentDidMount() { this.listenForTasks( ); }
Then , i create my listView :
<ScrollView style={{flex: 1}}> <ListView enableEmptySections={true} dataSource={this.state.dataSource} renderRow={this._renderItem.bind()} /> <Button onPress={this.listenForTasks.bind(this)}> <Text> Here </Text> </Button> </ScrollView>
I create a file ListItem `export default class ListItem extends Component { render(){ return(
)}
}`
But nothing is displayed.