0
我正确读取我的JSON数据并且打印正常,但是我无法将其设置为列表的数据源,因此我可以正确更新我的行。当打印this.state.dataSource时,它将以未定义的方式返回。我返回的JSON是一个数组。无法使用React-Native上的ListView更新数据源
export default class CoinCheckerRN extends React.Component {
constructor(props) {
super(props);
const dataSource = new ListView.DataSource({rowHasChanged: (row1, row2) => row1 !== row2});
this.state = {
dataSource: dataSource.cloneWithRows(['row 1', 'row 2']),
};
this._renderRow = this._renderRow.bind(this);
}
componentDidMount() {
getCryptocurrencyData().then(function(result) {
console.log('??????', result[0].name)
this.setState({ dataSource: this.state.dataSource.cloneWithRows(result)});
console.log('??', this.state.dataSource);
}).catch(function(error) {
console.log('!!!!!', error)
});
}
_renderRow(data) {
return (
<CoinCell coinName={'Bitcoin'} coinPrice={'£1,000'} coinPercentageChange={'-4.2%'}></CoinCell> )
}
render() {
return (
<View>
<ListView
enableEmptySections
ref={'resultListView'}
dataSource={this.state.dataSource}
renderRow={(data) => this._renderRow(data)}
renderSeparator={(sectionId, rowId) => <View key={rowId} style={styles.separator} />}
renderHeader={() => <Header />}
/>
</View>
);
}
}
任何帮助,将不胜感激
你看到任何东西在ListView中? –