ghj1234560123 2017-06-14 03:22 采纳率: 0%
浏览 5661

react的组件checkbox的使用问题

这是项目中以前人写的一个checkbox的组件,我现在想要表示选中,使用value等于true不对吗?应该怎么使用?
Checkbox = React.createClass({displayName: "Checkbox",
getDefaultProps: function() {
return {
on: 'true',
off: 'false'
};
},
getInitialState: function() {
return {
value: this.props.value || ''
};
},
componentDidMount: function() {
if (this.props.autofocus) {
return this.focus();
}
},
componentWillReceiveProps: function(nextProps) {
if (nextProps.value !== this.state.value) {
return this.setState({
value: nextProps.value
});
}
},
handleChange: function(e) {
var flag, value;
if (this.props.onBeforeChange) {
flag = this.props.onBeforeChange(value, this.oldValue, this.props.owner);
}
if (flag === false) {
return;
}
value = e.target.checked;
value = value ? this.props.on : this.props.off;
this.setState({
value: value
});
this._onUpdateValue(value);
return this.oldValue = value;
},
focus: function() {
return this.refs.textInput.focus();
},
render: function() {
var className, value;
className = classnames("x-checkbox-editor", this.props.className);
value = this.state.value || '';
return React.createElement("div", null,
React.createElement("input", React.__spread({}, this.props, {className: className,
ref: "textInput", checked: value === this.props.on || value.toLowerCase() == this.props.on,
value: value, onChange: this.handleChange}))
);
},
_onUpdateValue: function(value) {
Actions.updateValue(this.props.owner, this.props.target, value);
if (this.props.onChange) {
return this.props.onChange(value, this.oldValue, this.props.owner);
}
}
});

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料
    • ¥15 使用R语言marginaleffects包进行边际效应图绘制
    • ¥20 usb设备兼容性问题
    • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
    • ¥15 安装svn网络有问题怎么办