FlatList 不渲染
FlatList not Rendering
我正在尝试使用 FlatList,但 FlatList 无法正常工作。
-Android
这项工作
<FlatList
data={[{key: 'a'}, {key: 'b'}]}
renderItem={({item}) => <Text>{item.key}</Text>}
/>
这不起作用
<FlatList
data={this.state.dataSource}
keyExtractor={this._keyExtractor}
renderItem={({ item}) =>{console.log(item);}}
>
好的,我发现了问题,它在你的 componentWillMount
:
componentWillMount() {
return fetch('...')
.then((response) => {
return response.json();
})
.then((responseJson) => {
let ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 !== r2 });
this.setState({
isLoading: false,
dataSource: ***ds.cloneWithRows(responseJson).rowIdentities***
});
});
}
我做了 console.log(ds.cloneWithRows(responseJson))
就像你最初做的那样但是得到了这样的东西:
我们关心的数据在rowIdentities
我正在尝试使用 FlatList,但 FlatList 无法正常工作。 -Android
这项工作
<FlatList
data={[{key: 'a'}, {key: 'b'}]}
renderItem={({item}) => <Text>{item.key}</Text>}
/>
这不起作用
<FlatList
data={this.state.dataSource}
keyExtractor={this._keyExtractor}
renderItem={({ item}) =>{console.log(item);}}
>
好的,我发现了问题,它在你的 componentWillMount
:
componentWillMount() {
return fetch('...')
.then((response) => {
return response.json();
})
.then((responseJson) => {
let ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 !== r2 });
this.setState({
isLoading: false,
dataSource: ***ds.cloneWithRows(responseJson).rowIdentities***
});
});
}
我做了 console.log(ds.cloneWithRows(responseJson))
就像你最初做的那样但是得到了这样的东西:
我们关心的数据在rowIdentities