Javascript 输入是一个空元素标记,不能有'children',也不能使用'dangerlysetinerhtml'`
我尝试使用自定义的ReactJS单选按钮,但当我无法让它们呈现我的控制台上显示的某些错误时,在我的组件中,我有以下内容:Javascript 输入是一个空元素标记,不能有'children',也不能使用'dangerlysetinerhtml'`,javascript,reactjs,react-native,Javascript,Reactjs,React Native,我尝试使用自定义的ReactJS单选按钮,但当我无法让它们呈现我的控制台上显示的某些错误时,在我的组件中,我有以下内容: D.div({ className: 'stra-on-loss' }, D.span({ className: 'bet-title' }, 'On loss:'), ReactRadio({name: 'onLoss', onChange: this.updateOnLoss, defaultValue: this.state.onLossSelected
D.div({ className: 'stra-on-loss' },
D.span({ className: 'bet-title' }, 'On loss:'),
ReactRadio({name: 'onLoss', onChange: this.updateOnLoss, defaultValue: this.state.onLossSelectedOpt },
D.input({
type: 'radio',
className: 'stra-on-loss-return-to-base-radio',
value: 'return_to_base',
disabled: this.state.active
}, D.span(null, 'Return to base bet')),
D.input({
type: 'radio',
className: 'stra-on-loss-increase-bet-by',
value: 'increase_bet_by',
disabled: this.state.active
}, D.span(null, 'Increase bet by: '),
D.input({
type: 'text',
ref: 'onLossQty',
onChange: this.updateOnLossQty,
value: this.state.onLossIncreaseQty,
disabled: this.state.active || this.state.onLossSelectedOpt !== 'increase_bet_by' }
), D.span(null, 'x'))
)
)
但是我还有一个类,它被导入ReactRadio
,处理按钮:
return CreateReactClass({
displayName: 'reactRadio',
propTypes: {
name: PropTypes.string.isRequired,
value: PropTypes.string,
defaultValue: PropTypes.string,
onChange: PropTypes.func.isRequired
},
componentDidMount: function() {
this.update();
},
componentDidUpdate: function() {
},
update: function() {
if(this.props.defaultValue && !this.props.value)
this.setSelectedRadio(this.props.defaultValue);
},
change: function() {
if(!this.props.value)
this.props.onChange(this.getSelectedRadio());
},
getSelectedRadio: function() {
const radios = this.getRadios();
for(let i=0, length = radios.length; i < length; i++)
if(radios[i].checked)
return radios[i].value;
return null;
},
setSelectedRadio: function(value) {
const radios = this.getRadios();
for(let i = 0, length = radios.length; i < length; i++)
if(radios[i].value === value)
radios[i].checked = true;
},
getRadios: function() {
return this.getDOMNode().querySelectorAll('input[type="radio"]');
},
render: function() {
const self = this;
return D.div({ onChange: this.change },
React.Children.map(this.props.children, function(child) {
let newProps = {name: self.props.name};
if(child.props.children) {
React.Children.map(child.props.children, function (child) {
if (child.props.onChange) {
var childrenChange = child.props.onChange;
}
_.extend(child.props, {
onChange: function (e) {
e.stopPropagation();
if (childrenChange)
childrenChange();
}
});
});
}
if(self.props.value) {
if (child.props.value !== self.props.value)
newProps.disabled = true;
else {
newProps.checked = true;
newProps.readOnly = true;
}
}
_.extend(child.props, newProps);
return child;
})
)
}
});
返回CreateReactClass({
displayName:'reactRadio',
道具类型:{
名称:PropTypes.string.isRequired,
值:PropTypes.string,
defaultValue:PropTypes.string,
onChange:PropTypes.func.isRequired
},
componentDidMount:function(){
这个.update();
},
componentDidUpdate:函数(){
},
更新:函数(){
if(this.props.defaultValue&!this.props.value)
this.setSelectedRadio(this.props.defaultValue);
},
更改:函数(){
如果(!this.props.value)
this.props.onChange(this.getSelectedRadio());
},
getSelectedRadio:函数(){
const radios=this.getRadios();
for(设i=0,length=radios.length;i
当我访问我的浏览器时,我在控制台中得到以下信息&组件没有被加载:未捕获不变冲突:输入是一个无效的元素标记,不能有子元素
,也不能使用危险的HTML
。检查AutoWebWidget的渲染方法。