ParseReact icon indicating copy to clipboard operation
ParseReact copied to clipboard

cloneWithRows can't work with array

Open sihemhssine opened this issue 8 years ago • 0 comments

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(

{this.props.task.name}
)}

}`

But nothing is displayed.

sihemhssine avatar Aug 02 '17 11:08 sihemhssine