React-Native Updating List View Datasource

React-Native Updating List View DataSource

Try this:

pressRow(rowData){

var newDs = [];
newDs = this.state.ds.slice();
newDs[0].Selection = newDs[0] == "AwayTeam" ? "HomeTeam" : "AwayTeam";
this.setState({
dataSource: this.state.dataSource.cloneWithRows(newDs)
})

}

This should make a copy of the array, which can then be modified independently of the original array in this.state.ds.

Can't update dataSource with ListView on React-Native

Managed to fix it with one of the previous answers listed here with a slight tweak:

 _getCoinData() {
getCryptocurrencyData().then(function(result) {

const ds = new ListView.DataSource({rowHasChanged: (row1, row2) => row1 !== row2});
this.setState({
dataSource: ds.cloneWithRows(result),
jsonData: result
});

console.log('!!!', this.state.jsonData);
}.bind(this))
}

React Native: ListView.DataSource is not updating

In your code, you only set your dataSource in contructor of FormativeRevisionList, this mean FormativeRevisionList will only render the given movies when your first render it.

To render new list after you press Get Topics button , you need to set the dataSource again when it receive new props, this can be achieve by setting it in FormativeRevisionList componentWillReceiveProps

  componentWillReceiveProps(nextProps) {
if (nextProps.movies !== this.props.movies) {
this.setState({
dataSource: this.state.dataSource.cloneWithRows(nextProps.movies)
})
}
}

You can read more about componentWillReceiveProps from here

react native ListView datasource not updating

So after a lot of reading and changes the listview is now updating.
According to this post

Changes the ds declaration to:

this.ds = new ListView.DataSource({rowHasChanged: (row1, row2) => row1 !== row2});

So changed my changeisComplete method

changeisCompleted=(rowData,rowId)=>{

var newDs = [];
newDs = this.state.todoListArray.slice();
newDs[rowId].isCompleted =!newDs[rowId].isCompleted;

this.setState({
dataSource: this.ds.cloneWithRows(this.state.todoListArray),
todoListArray:newDs
})

}

I'm not sure if this is the right way to do this,but anyway it works and now the checkbox is getting changed

Thanks



Related Topics



Leave a reply



Submit