parse-community / ParseReact

Seamlessly bring Parse data into your React applications.
https://parseplatform.org
Other
1.3k stars 209 forks source link

cloneWithRows can't work with array #187

Open sihemhssine opened 6 years ago

sihemhssine commented 6 years ago

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 (

); } ****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()} />

`

I create a file ListItem `export default class ListItem extends Component { render(){ return(

{this.props.task.name}
)}

}`

But nothing is displayed.