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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 vmware exsi重置后登不上
    • ¥15 易盾点选的cb参数怎么解啊
    • ¥15 MATLAB运行显示错误,如何解决?
    • ¥15 c++头文件不能识别CDialog
    • ¥15 Excel发现不可读取的内容
    • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
    • ¥20 yolov5自定义Prune报错,如何解决?
    • ¥15 电磁场的matlab仿真
    • ¥15 mars2d在vue3中的引入问题
    • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面