RN 使用Checkbox实现多选

这个多选功能使用的是Ant Design Mobile RN 库中的 Checkbox来实现,话不多说直接上代码

1、引入 import { Checkbox,} from '@ant-design/react-native';

2、声明 const CheckboxItem = Checkbox.CheckboxItem;

3、使用

//  使用map实现多选
    private showMap() {
        let dataList: any[] = this.state.data
        if (dataList && dataList.length) {

            return dataList.map((item, index) => {
                return (
                    <CheckboxItem
                        key={index}
                        style={{ height: 70 }}
                        onChange={(event: any) => {
                            let bidDocId: number = item.bidDocId
                            // 保存选中结果list
                            let oData: any = this.state.bidDocIdList;
                            // 如果是选中状态 则判断bidDocIdList是否含有该对象,若无则添加
                            if (event.target.checked) {
                                if (!oData.includes(bidDocId)) {
                                     oData.push(bidDocId)
                                }

                            } else {
                            // 如果是未选中状态 则判断bidDocIdList是否含有该对象,若有则删除
                                if (oData.includes(bidDocId)) {
                                    let indexC = oData.indexOf(bidDocId)
                                    oData.splice(indexC,1)
                                }

                            }
                            UtilsSuperCommon.logWarn(this.state.bidDocIdList);
                        }}
                    >
                        {/* 自定义控件 */}
                        <View style={{ flex: 1, paddingVertical: 15, flexDirection: 'row' }}>
                            <SelBidderView
                                bidderHeadImg={item.iconUrl}
                                bidderName={item.userName}
                            />
                        </View>
                    </CheckboxItem>
                );
            })
        }

    }

 

转载于:https://www.cnblogs.com/lijianyi/p/11481614.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值