Javascript React和jQuery移动渲染问题
我正在基于React.js为render jQuery Mobile Objet开发一些组件 我创建了以下类:Javascript React和jQuery移动渲染问题,javascript,jquery,mobile,reactjs,Javascript,Jquery,Mobile,Reactjs,我正在基于React.js为render jQuery Mobile Objet开发一些组件 我创建了以下类: var JQueryMobileInputText = React.createClass({ displayName: 'JQueryMobileInputText', getDefaultProps: function() { return {'name':'n'+uniqid(), 'label':'', 'type':'text', value:'',
var JQueryMobileInputText = React.createClass({
displayName: 'JQueryMobileInputText',
getDefaultProps: function() {
return {'name':'n'+uniqid(), 'label':'', 'type':'text', value:'',
'hideLabel':false
}
},
render: function() {
var label = React.createFactory('label');
var input = React.createFactory('input');
var classStr = this.props.class;
if (this.props.hideLabel)
{
classStr += (classStr == "" ? '' : ' ') + 'ui-hide-label';
}
return (
React.DOM.div({'data-role':'fieldcontain', 'class':classStr},
label({'for':this.props.name}, this.props.label),
input({'type':this.props.type, name:this.props.name,
id:this.props.name, value:this.props.value,
placeholder:this.props.label}
)
));
}
});
JQueryMobileInputText = React.createFactory(JQueryMobileInputText);
我这样称呼它:
render: function() {
return React.DOM.div(null,
JQueryMobileForm(null,
JQueryMobileInputText({name:'texto1', label:'Texto', hideLabel:true})
),
);
}
我希望得到以下HTML结果:
<div data-role="fieldcontain" class="ui-hide-label">
<label for="texto1">Texto</label>
<input type="text" name="texto1" id="texto1" value=""
placeholder="Texto"/>
</div>
但我得到了一些不同于此的东西:
<div data-role="fieldcontain" data-reactid=".0.0.1.0.5.0"
class="ui-field-contain">
<label data-reactid=".0.0.1.0.5.0.0">Texto</label>
<div class="ui-input-text ui-body-inherit ui-corner-all ui-shadow-inset">
<input type="text" name="texto1" id="texto1" value="" placeholder="Texto" data-reactid=".0.0.1.0.5.0.1">
</div>
</div>
我的问题是:
为什么没有添加标签的for属性?
为什么我的div的类没有ui隐藏标签字符串?
为什么要为输入添加新的div?
搜索internet我解决了我的问题: 1为什么未添加标签的“for”属性 以下是解决方案: 2为什么我的div的类没有ui隐藏标签字符串 以下是解决方案:
对于数字1,根据这个答案,您需要使用htmlFor而不是For 在第二个问题上,如果你交换,它能工作吗 React.DOM.div{'data-role':'fieldcontain','class':classStr},对于React.DOM.div{'data-role':'fieldcontain','className':classStr} 最后,我建议页面上还有其他代码处理类名,并在输入周围添加额外的div,因为上面发布的代码中没有提到这两个
除了React,您还使用其他库吗?您是否可以在应用程序外部(例如在a中)测试组件?是的,我正在使用jQuery Mobile。我将尝试将其添加到JSFIDLE并将链接放在这里。我无法将其放在JSFIDLE中,但我会将其发布到我的服务器中。有帮助吗?