react+antdesign中switch选择根据传入值标定状态

1.显示


  getColumns = () => {
    const { roleKV } = this.props.content;
    const { checkedChildren,unCheckedChildren,switchflag,textflag} = this.state;
    return [
      {title:'商户名称',dataIndex:'f_merchtname'},
      {title:'渠道类型',
      dataIndex:'f_name',
      },
      {title:'开通状态',align:'center',dataIndex:'fUse',
      render: (text, record, index) => (
        console.log("text = " + text),
          <Switch defaultChecked={text}  onChange={(switchflag)=>this.handleSwitch(switchflag,record)}/>
      )}

    ]
  }

2.提交

  handleSwitch = (switchflag,record) => {
    console.log("merctchannelupdate record = " + record.fUse);
    // const {switchBox} = this.state;
    // this.setState({
    //   switchflag: true
    // }); 

    ajax({
      url: 'merctchannel_update',
      fUse: switchflag ? "1" : "0",
      fChaneltype:record.fChaneltype,
      listKey:'merctchannelupdate'
    },
    ()=>{
      this.handleSearch();
      message.success("更新成功")
  });
   
  }

3.效果
在这里插入图片描述
在这里插入图片描述
4.日志
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_40550118/article/details/108574663