react 使用antd的多选功能做一个单选与全选效果

一个小而简单的单选全选功能,其实官网已经给出效果了,不过是我多做了些复合用法

 

addorupdatemodal.jsx
import React from "react";
import {Modal,Table,Button,Checkbox,Card,Popconfirm } from 'antd';
import LoadingMixin from '../../../libs/loading.common.mixin';
import RequestMixin from '../../../libs/request.mixin';
import NotificationMixin from '../../../libs/notification.mixin';
import Helper from '../../../libs/helper';
import './index.css';

const { Meta } = Card;
const CheckboxGroup = Checkbox.Group;
export default React.createClass({
    mixins: [LoadingMixin, NotificationMixin, RequestMixin],
    propTypes: {
        onManualClose:React.PropTypes.func,
        onOk: React.PropTypes.func,
        onCancel: React.PropTypes.func,
        title: React.PropTypes.string,
        item: React.PropTypes.object
    },
    getInitialState() {
        return {
            item: this.props.item  && this.props.item || {},
            data: [],
            userObj: {},
            deleteList:[],
            indeterminate: false,
            checkAll: false,
            checkedList:[]
        };
    },
    componentWillMount() {
        this.fetch();
    },
    fetch() {
        // console.log("11111111111------------》",this.props.item.frameid);
        this.post({
            url: "Api/historyPush/module/frame/key/dac509bd90a82719a3569291e12c24a6f1af4bac",
            param: {
                frameid: this.props.item.frameid
                // frameid:'32frame_tj1'
            },
            noLoading: true
        }).then(result=> {
            // console.log("result-----------------",result);
            this.setState({data: result.result || []});
        });
        // this.get({
    
        //     url: "Api/lists/module/user/key/dac509bd90a82719a3569291e12c24a6f1af4bac",
        //     param: {
    
        //     },
        //     noLoading: true
        // }).then(result=> {
    
        //     let userObj = {};
        //     result.result && result.result.map(item => {
    
        //         userObj[item.id] = item.nickname;
        //     });
        //     this.setState({userObj: userObj|| {}});
        // });
    },
    hideModal() {
        this.props.onCancel && this.props.onCancel();
    },
    onChange(checkedList){
        // console.log('checked = ', checkedList);
        this.setState({
            checkedList:checkedList,
            indeterminate: !!checkedList.length && (checkedList.length < this.state.data.length),
            checkAll: checkedList.length === this.state.data.length,
        });

    },
    onCheckAllChange(e){
        // console.log("全选1",e.target.checked);
        // console.log("全选2",this.state.data);
        let dataList =[]
        for(var i=0;i<this.state.data.length;i++){
            dataList[i]=this.state.data[i].imgid
        }
        // console.log("dataList--------",dataList)
        this.setState({
            checkedList: e.target.checked ? dataList : [],
            indeterminate: false,
            checkAll: e.target.checked,
        });
    },
    handleClose(record) {
        var that = this;
        if (this.state.checkedList==null||this.state.checkedList.length==0) {
            that.error("请选择要删除的图片");
            return false;
        };
        // console.log("删除的图片",this.props.item.frameid,this.state.checkedList);
        this.post({
            url: "Api/clearCache/module/frame/key/dac509bd90a82719a3569291e12c24a6f1af4bac",
            param: {
                frameid:this.props.item.frameid,
                imglist: this.state.checkedList
            },
            noLoading: true
        }).then(result=> {
            if (result.result) {
                that.success("操作成功");
                that.fetch();
            }
        });
    },
    render() {
        let isMainObj = {
            1 : "是",
            0 : "否"
        }
        let columns = [
            { title: '用户', dataIndex: 'userid', key: 'userid', width: '20%',
                render: (text, record) => {
                    return (
                        
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值