【问题标题】:FlatList react nativeFlatList 反应原生
【发布时间】:2017-10-31 15:18:41
【问题描述】:

我的 FlatList 有问题,我无法滚动列表... 它是块,我的列表足以滚动

const tab_ad = [
    {"id": 0, "Price": 100000, "key": 0},
    {"id": 1, "Price": 100000, "key": 1},
    {"id": 2, "Price": 100000, "key": 2},
    {"id": 3, "Price": 100000, "key": 0},
    {"id": 4, "Price": 100000, "key": 1},
    {"id": 5, "Price": 100000, "key": 2},
    {"id": 6, "Price": 100000, "key": 0},
    {"id": 7, "Price": 100000, "key": 1},
    {"id": 8, "Price": 100000, "key": 2},   
]

export default class Event extends Component {
renderItem(item) {
        return (
            <Image source={path_default_picture} style={{width: 50, height: 50, margin: 5}}/>
        );
    }

render() {
    return (
        <View style={{flex: 1}}>
            <FlatList
                horizontal
                data={tab_ad}
                renderItem={(item) => this.renderItem(item)}
                keyExtractor={(item, index) => index}
             />
         </View>
    );
}

react-native-cli: 2.0.1 反应原生:0.49.3

有人可以帮助我吗?

【问题讨论】:

  • 列表没有滚动?
  • 我在世博小吃中试过你的代码。它在那里工作得很好。只是将图像更改为视图。 snack.expo.io/HkcAOXLCb
  • 我试过你的代码,它在我的最后工作正常。

标签: react-native jsx react-native-flatlist


【解决方案1】:

FlatList 忽略具有相同键的值。玩了一会儿才发现。很可能问题不在于未启用滚动,而是您具有相似的值。

您能否尝试确保密钥在所有列表中都是唯一的?

如果没有,请用问题做点心

【讨论】:

  • 但是他用数组的索引作为key。
  • 不错,没看到。
猜你喜欢
  • 2018-12-02
  • 2018-04-17
  • 2019-04-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-04
相关资源
最近更新 更多