reactjs - 如何删除相同值的多个单选按钮选择-react
问题描述
我有相同的值重复 3-4 次,如果我选择第一个值,其他相关值正在被选中我不想选择所有相同的值
前任:
const tuitions = [
{ value: 'ValueA', key: 'KeyA', name: 'Name A',timestamp:"2020-05-07T10:01:16.776+0000" },
{ value: 'ValueB', key: 'KeyB', name: 'Name B', timestamp:"2020-05-07T09:01:16.776+0000" },
{ value: 'ValueC', key: 'KeyC', name: 'Name C' , timestamp:"2020-05-07T08:22:55.546+0000" },
{ value: 'ValueA', key: 'KeyA', name: 'Name A', timestamp:"2020-05-07T08:22:16.566+0000" },
{ value: 'ValueA', key: 'KeyA', name: 'Name A', timestamp:"2020-05-07T08:01:16.77+0000" },
];
const RadioButton = (props) => (
<label>
<input
type="radio"
name="Schools"
value={props.value}
onChange={props.onChange}
/>
{props.name}
</label>
);
class Thingy extends React.Component {
_RadioClickHandler = (e, name) => {
}
render() {
return (
<div>
{tuitions.map(item=>(
<RadioButton
value={item.value}
key={item.key}
name={item.name}
onChange={e => this._RadioClickHandler (e, item.name) }
/>
)
)}
</div>
);
}
}
// Render it
ReactDOM.render(
<Thingy />,
document.body
);
如果我选择名称 A,所有名称 A 相关的东西都会被检查,如何避免这种情况。
解决方案
If you pass same value and select one of them all the other will be selected. That's how it works. You must need to pass unique value
Updated
Suppose the display name is same but you should pass the value unique. If you need you can make them ValueA1
ValueA2
ValueA3
推荐阅读
- javascript - RXJS 通过属性“id”组合/合并两个 Observable 数组
- java - Selenium:如果选择标签包含样式=“显示:无;”,如何从下拉列表中选择选项
- javascript - Lightning 组件,在控制器中检索查找记录值
- python - 如何将此 Python2.x 代码转换为 Python3.x?
- reactjs - 当光标在 React JS 中的组件上快速移动时如何管理状态值?
- sql - 从所有项目相互引用的交叉引用表中获取唯一行
- c# - UWP MapControl.Location 绑定无法正常工作
- compilation - 使用 GFortran 在同一个文件中编译模块和主程序?
- python - 我需要一个模块在我的系统上不起作用的解决方案
- python - 从图像分割中保存单个片段