【发布时间】:2017-08-07 21:27:44
【问题描述】:
我是 reactJS 的新手,我正在学习如何使用 pup 样板来使用单选按钮。
我正在尝试将icon 的输入无线电代码添加到/imports/ui/components/DocumentEditor/DocumentEditor.js,这就是我目前所处的位置:
<FormGroup>
<ControlLabel>Icon</ControlLabel>
{['mobile', 'tablet', 'laptop', 'tv'].map((el, i) =>
<Radio
ref={icon => (this.icon = icon)}
key={i}
name="icon"
value={el}
onChange={e => this.handleRadioSelection(e)}
inline>
<i className={`fa fa-3x fa-${el}`}></i>
</Radio>
)}
</FormGroup>
处理程序:
handleRadioSelection (e) {
const { name, value } = e.target;
this.setState({
[name]: value
});
}
架构(使用simpl-schema)
icon: {
type: String,
label: 'The icon that better represents the platform.',
allowedValues: ['mobile', 'tablet', 'laptop', 'tv'],
},
我有两个问题:
- 我的数组是硬编码的,我想从架构中导入 allowedValues 数组,怎么做?
- 我的 onChange 事件处理程序不起作用,缺少什么?
注意:在网页上,我看到单选按钮在选择单选时发生变化,但新值没有保存。
【问题讨论】:
标签: javascript reactjs meteor simple-schema