class RadioGroup extends React.Component {
getRadioComponent(item, index) {
return <div className="custom-radio" key={this.props.name + '-' + index}>
<input id={item.id} type="radio" name={this.props.name} value={item.value} checked={this.props.checkedValue == item.value} disabled={item.disabled} onChange={this.props.checkChanged} />
<label htmlFor={item.id} disabled={item.disabled}>{item.text}</label>
</div>
} render() {
let
className = this.props.isHorizontal ? 'horizontal' : 'normal',
items = this.props.items || [];
return <div id={this.props.id} className={className}>
{
items.map((item, index) => {
if (this.props.isHorizontal)
return this.getRadioComponent(item, index);
else
return <div key={index}>{this.getRadioComponent(item, index)}</div>;
})
}
</div>
}
} export default RadioGroup;

使用:

 const type = {
Auto: 0,
Use: 1
}
this.state = {
defaultCheckedValue: type.Use,
radioOptions: [
{
id: "id-auto",
value: type.Auto,
text: 'auto'
{
id: "id-use",
value: type.Use,
text: 'use'
}],
} onActionSelectedChange(e, args) {
this.setState(Object.assign(this.state, {
defaultCheckedValue: parseInt(e.currentTarget.value),
}));
}
 <RadioGroup
id={"id"}
name={"dqhan-name"}
isHorizontal={true}
items={this.state.radioOptions}
checkedValue={this.state.defaultCheckedValue}
checkChanged={this.handleRadioChange}
/>

React封装RadioGroup的更多相关文章

  1. 基于 React 封装的高德地图组件,帮助你轻松的接入地图到 React 项目中。

    react-amap 这是一个基于 React 封装的高德地图组件,帮助你轻松的接入地图到 React 项目中. 文档实例预览: Github Web | Gitee Web 特性 ️ 自动加载高德地 ...

  2. 如何基于 React 封装一个组件

    如何基于 React 封装一个组件 前言 很多小伙伴在第一次尝试封装组件时会和我一样碰到许多问题,比如人家的组件会有 color 属性,我们在使用组件时传入组件文档中说明的属性值如 primary , ...

  3. react封装简单的浏览器顶部加载进度条全局组件

    在项目中经常会有在请求前后加loading或者加加载进度条,一般这些组件都会抽离出来作为全局组件 进度条的插件貌似都不是很符合自己项目中的需求,于是.. 参考nprogress样式,自己在项目中封装组 ...

  4. react封装组织架构递归树

    想用react实现一个递归树,但一些框架里面的有些不符合需求,于是自己写了个,功能比较简单,欢迎批评指正.. react实现这样一个组织架构递归树,下级部门的收起和展开,点击部门名称时请求接口获取下级 ...

  5. 使用react封装评论组件

    首先看我的效果图 我在评论框中输入数据,会在页面进行显示 这个效果图我们进行拆分就是,一个评论组件,一个大的评论列表组件,一个小的评论组件 首先整个页面中有的是我们的评论组件和列表组件 我们输入评论点 ...

  6. react封装通用tab组件

    import React, { Component } from 'react' import PropTypes from 'prop-types' import _ from 'lodash' i ...

  7. react封装基于axios的API请求

    一.最近做的一个后台管理项目,基于antd-pro做的,需要封装基于axios请求,便于开发,直接上代码. import axios from 'axios'; export const Method ...

  8. 在ASP.NET MVC项目中使用React

    (此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:最近在开发钉钉的微应用,考虑到性能和UI库的支持,遂采用了React来开发前端. 目前 ...

  9. React使用笔记(3)-React Event Listener

    Date: 2015-11-28 12:18 Category: Web Tags: JavaScript Author: 刘理想 [toc] 1. 构造基本结构 首先,我们先创建一个按钮,一个输入框 ...

随机推荐

  1. 【Android】6.4 DatePickerDialog和TimePickerDialog

    分类:C#.Android.VS2015: 创建日期:2016-02-08 一.简介 在Android应用中,日期选择对话框和时间选择对话框是分别提供的. 日期选择对话框(DatePickerDial ...

  2. android即时消息处理机制

    在android端做即时消息的时候.遇到的坑点是怎么保证消息即时性,又不耗电.为什么这么说呢?      原因是假设要保证消息即时性.通常有两种机制pull或者push. pull定时轮询机制,比較浪 ...

  3. 基于jquery的邮箱输入联想插件开发

    js代码: /*create by code_bunny 20140701 973295131@qq.com https://github.com/OOP-Code-Bunny */ (functio ...

  4. ny269 VF

    VF 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 Vasya is the beginning mathematician. He decided to make ...

  5. Spark Streaming使用Kafka保证数据零丢失

    来自: https://community.qingcloud.com/topic/344/spark-streaming使用kafka保证数据零丢失 spark streaming从1.2开始提供了 ...

  6. 终端模拟工具:Xshell 4

    终端模拟工具:Xshell 4 2016-09-20 目录 1 安装 2 配置 3 命令 Xshell 是一个强大的安全终端模拟软件,它支持SSH1, SSH2, 以及Microsoft Window ...

  7. 解析html文档的java库及范例

    用这个工具jsoup <groupId>org.jsoup</groupId> <artifactId>jsoup</artifactId> <v ...

  8. python 集合比较(交集、并集,差集)集合方法大全

    python的set和其他语言类似, 是一个无序不重复元素集, 基本功能包括关系测试和消除重复元素. 集合对象还支持union(联合), intersection(交), difference(差)和 ...

  9. webRTC开启摄像头

    配置htts之后就可以开启webRTC了. <!DOCTYPE html> <html> <head> <title>OpenCamera</ti ...

  10. linux命令之数据盘格式化挂载

    1,查看数据盘 在没有分区和格式化数据盘之前,使用”df -h “命令是无法看到数据盘的,可以通过 fdisk -l 查看机器情况(找出所有硬盘个数及设备名称)  提示:若没有发现/dev/xvdb ...