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 ue5 .3之前好好的现在只要是激活关卡就会崩溃
    • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
    • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
    • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
    • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
    • ¥15 python爬取bilibili校园招聘网站
    • ¥30 求解达问题(有红包)
    • ¥15 请解包一个pak文件
    • ¥15 不同系统编译兼容问题
    • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?