Py学习  »  MongoDB

通过react从MongoDB中检索数据

Yuri Nunes • 5 年前 • 307 次点击  

我在node,react和mongoddb(mongoose)中开发了这个简单的应用程序,在这里我可以注册用户,然后编辑用户的信息。问题是,在显示刚注册的内容(编辑组件)时,我被卡住了。我想在编辑组件字段中显示用户信息,这与注册组件完全相同。我不知道怎样才能把这个信息拿回来并显示出来。

class Register extends React.Component {
 constructor(props) {
    super(props);
    this.state = {
        email: '',
        telephone:''

    }
}

onEmailChange = (event) => {
    this.setState({email: event.target.value})
}

onTelephoneChange = (event) => {
    this.setState({telephone: event.target.value})
}

render () {
return (
  <article className="br3 ba b--black-10 mv4 w-100 w-50-m w-30-l shadow-5 center">  
            <main className="pa4 black-80">
            <div className="measure">
                <fieldset id="email" className="ba b--transparent ph0 mh0">
                    <div className="mt3">
                        <label className="db fw6 lh-copy f6">Email</label>
                        <MaskedInput 
                            className="  borderColour pa2 input-reset ba bg-transparent hover-bg-black hover-white w-100" 
                            placeholder='john@email.com'
                            id="email"
                            required
                            onChange={this.onEmailChange}
                            /> 
                        <label className="db fw6 lh-copy f6">Zona</label>
                            <div className="mv3">
                        <label className="db fw6 lh-copy f6">Telefone</label>
                        <MaskedInput
                            className=" borderColour b pa2 input-reset ba bg-transparent hover-bg-black hover-white w-100"
                            placeholder="(41) 99989-0909" 
                            onChange={this.onTelephoneChange}
                            /> 
                    </div>

    </div>
            </div>
        </main>
    </article>

);
}
}

我试图缩短我的代码,因为其他字段几乎是相同的。 如果有人能帮我,我会很高兴的!

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/38200
 
307 次点击  
文章 [ 1 ]  |  最新文章 5 年前