ReactJS-无法获取有关输入的信息
我是新来的。我不知道如何获得输入字段的值。我向您展示如何编写组件代码的最佳方式:ReactJS-无法获取有关输入的信息,reactjs,components,refs,Reactjs,Components,Refs,我是新来的。我不知道如何获得输入字段的值。我向您展示如何编写组件代码的最佳方式: create class inputFields extends React.Component{ getAllInformationAsJSON() { return { company : this.refs.company.getText(), street : this.refs.street.getText(), plz : this.refs
create class inputFields extends React.Component{
getAllInformationAsJSON() {
return {
company : this.refs.company.getText(),
street : this.refs.street.getText(),
plz : this.refs.plz.getText(),
city : this.refs.city.getText(),
description : this.refs.description.getText(),
}
}
render() {
return (
<div style={cssStyle.bodyStyle}>
<FormComponentText ref="company" placeholder= {Translation.Location.firmaPlaceholder}/>
<FormComponentText ref="street" placeholder={Translation.Location.streetPlaceholder}/>
<FormComponentText ref="plz" width='20%' placeholder={Translation.Location.PLZPlaceholder}/>
<FormComponentText ref="city" width='80%' placeholder={Translation.Location.placePlaceholder}/>
<FormComponentArea ref="description" rows='7' placeholder={Translation.Location.descriptionPlaceholder}/>
<div><button onClick={this.getAllInformationAsJSON}>Test</button></div>
</div >
)
}
}
addChild(component) {
viewTitle = Translation.Settings.User.title;
viewConfig.view.window.width = 600;
viewConfig.view.window.height = 400;
*bodyInfo* = <**inputFields** />;
this.props.addComponentToView(<JSPanel idInfo="" config={viewConfig} title={viewTitle} bodyInfo={*bodyInfo*}/>);
}
create class inputFields.Component{
getAllInformationAsJSON(){
返回{
公司:this.refs.company.getText(),
street:this.refs.street.getText(),
plz:this.refs.plz.getText(),
城市:this.refs.city.getText(),
description:this.refs.description.getText(),
}
}
render(){
返回(
试验
)
}
}
如果我在html文档中呈现它,它工作得很好
render(){
return (<inputFields />)
}
render(){
返回()
}
然后,如果调用该函数,我将获得所有信息。但我想把这个组件放到另一个组件中:
create class inputFields extends React.Component{
getAllInformationAsJSON() {
return {
company : this.refs.company.getText(),
street : this.refs.street.getText(),
plz : this.refs.plz.getText(),
city : this.refs.city.getText(),
description : this.refs.description.getText(),
}
}
render() {
return (
<div style={cssStyle.bodyStyle}>
<FormComponentText ref="company" placeholder= {Translation.Location.firmaPlaceholder}/>
<FormComponentText ref="street" placeholder={Translation.Location.streetPlaceholder}/>
<FormComponentText ref="plz" width='20%' placeholder={Translation.Location.PLZPlaceholder}/>
<FormComponentText ref="city" width='80%' placeholder={Translation.Location.placePlaceholder}/>
<FormComponentArea ref="description" rows='7' placeholder={Translation.Location.descriptionPlaceholder}/>
<div><button onClick={this.getAllInformationAsJSON}>Test</button></div>
</div >
)
}
}
addChild(component) {
viewTitle = Translation.Settings.User.title;
viewConfig.view.window.width = 600;
viewConfig.view.window.height = 400;
*bodyInfo* = <**inputFields** />;
this.props.addComponentToView(<JSPanel idInfo="" config={viewConfig} title={viewTitle} bodyInfo={*bodyInfo*}/>);
}
addChild(组件){
viewTitle=Translation.Settings.User.title;
viewConfig.view.window.width=600;
viewConfig.view.window.height=400;
*bodyInfo*=;
this.props.addComponentToView();
}
JSP小组成员:
class JSPanel extends React.Component {
constructor(props) {
super(props);
this.sendInformation = this.sendInformation.bind(this);
}
sendInformation() {
var test = findDOMNode("TEST");
request("/componente/location", requestData.POST, '{info:test}', requestData.CONTENT_JSON)
.then(token => {
}).catch(err => console.log(err))
}
render() {
return this.state.showImage ? (<div ref="ich" style={this.state.css.view}>
<div style={this.state.css.body}>
{this.props.**bodyInfo**}
</div>
</div>
) : (<div></div>)
}
class JSPanel扩展了React.Component{
建造师(道具){
超级(道具);
this.sendInformation=this.sendInformation.bind(this);
}
发送信息(){
var测试=findDOMNode(“测试”);
请求(“/component/location”,requestData.POST,{info:test}”,requestData.CONTENT_JSON)
。然后(令牌=>{
}).catch(err=>console.log(err))
}
render(){
是否返回此.state.showImage(
{this.props.*bodyInfo**}
) : ()
}
我想要的是通过函数sendInformation()从输入中获取信息
我希望这很清楚我的意思,任何人都能帮助我
最好的问候这样做的一个好方法是在用户键入值时将值存储在状态中这样做的一个好方法是在用户键入值时将值存储在状态中你遵循了谁的教程来获得此结果?我建议你深入查看facebook react Docs这是错误的方法吗?我没有遵循低一些教程。你遵循了谁的教程来获得此结果?我建议你深入查看facebook react Docs这是错误的吗?我没有遵循一些教程。好的,但是如何从sendInformation()中的组件获取状态信息函数?这是我最大的问题。好的,但是如何从sendInformation()函数中的组件获取状态信息?这是我最大的问题。