如何将多个 FlatList 项目发送到 React Native 中的另一个屏幕?

How to send multiple FlatList items to another screen in ReactNative?

我有这些数据,我知道如何使用 Flatlist 显示数据,但如何添加多select 功能?

用户可以 select 多个项目,我如何使用道具将 selected 项目传递到另一个屏幕?

const goods = [{
        key: 1,
        item: 'Laptops & accessories'
    },
    {
        key: 2,
        item: 'Mobiles & accessories'
    },
    {
        key: 3,
        item: 'Television'
    },
    {
        key: 4,
        item: 'Washing Machine'
    },
    {
        key: 5,
        item: 'Air Conditioners'
    },
    {
        key: 6,
        item: 'Refrigerators'
    },
]

您可以简单地在列表中添加一个字段,例如 selected,如下所示,如果 selected,则相应地显示图像,然后显示复选标记图像,否则显示非复选标记图像。

const goods = [{
        key: 1,
        item: 'Laptops & accessories',
    selected: false
    },
    {
        key: 2,
        item: 'Mobiles & accessories',
    selected: false
    },
    {
        key: 3,
        item: 'Television',
    selected: false
    },
    {
        key: 4,
        item: 'Washing Machine',
    selected: false
    },
    {
        key: 5,
        item: 'Air Conditioners',
    selected: false
    },
    {
        key: 6,
        item: 'Refrigerators',
    selected: false
    },
]

并且当 select 任何项目时,则为该特定项目设置 selected = true。您可以使用此

将 selected 项目作为道具发送到下一个屏幕
this.props.navigation.navigate('screen2', { item });

要在屏幕 2 上检索,请使用以下代码

this.props.navigation.state.params.item;