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);
}
}
});

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问