最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。
In this section we will discuss how to use forms in React.
HTML form elements are different from other DOM elements in React because form elements are born with some internal state.
In HTML, things like input, , and These types of form elements maintain their own state and are updated based on user . However, in React, mutable states are usually saved in the component’s state properties and can only be used with setState() update the method.
3.22.1. A simple example ¶
In the example, we set up the input box input value value = {this.state.data} . We can update the state when the value of the input box changes. We can use it. onChange events to monitor input change and modify state .
React instance ¶
classHelloMessageextendsReact.Component{constructor(props){super(props);this.state={value:'Hello Runoob!'};this.handleChange=this.handleChange.bind(this);}handleChange(event){this.setState({value:event.target.value});}render(){varvalue=this.state.value;return {value}
;}}ReactDOM.render( ,document.getElementById('example')); The above code will render a value of Hello Runoob! of input Element and pass through the onChange the event response updates the value entered by the user.
3.22.2. Example 2 ¶
In the following example, we will show you how to use a form on a subcomponent. onChange method will trigger state and pass the updated value to the input box of the child component value come up and re-render the interface.
You need to create an event handle (handleChange) in the parent component as a prop (updateStateProp) pass it to your subcomponents.
React instance ¶
classContentextendsReact.Component{render(){return {this.props.myDataProp}
;}}classHelloMessageextendsReact.Component{constructor(props){super(props);this.state={value:'Hello Runoob!'};this.handleChange=this.handleChange.bind(this);}handleChange(event){this.setState({value:event.target.value});}render(){varvalue=this.state.value;return ;}}ReactDOM.render( ,document.getElementById('example')); 3.22.3. Select drop-down menu ¶
In React, do not use the selected property, while at the root select use on the label value property to represent the selected item.
React instance ¶
classFlavorFormextendsReact.Component{constructor(props){super(props);this.state={value:'coconut'};this.handleChange=this.handleChange.bind(this);this.handleSubmit=this.handleSubmit.bind(this);}handleChange(event){this.setState({value:event.target.value});}handleSubmit(event){alert('Your favorite flavor is:'+this.state.value);event.preventDefault();}render(){return({this.handleSubmit}> <label> Choose your favorite website <selectvalue={this.state.value}onChange={this.handleChange}> <optionvalue="gg">Googleoption> <optionvalue="rn">Runooboption> <optionvalue="tb">Taobaooption> <optionvalue="fb">Facebookoption> select> label> <inputtype="submit"value="submit to"/> form>);}}ReactDOM.render(<FlavorForm/>,document.getElementById('example')); 3.22.4. Multiple forms ¶
When you have to deal with multiple input element, you can add a name property to make the handler function based on the event.target.name to choose what to do.
React instance ¶
classReservationextendsReact.Component{constructor(props){super(props);this.state={isGoing:true,numberOfGuests:2};this.handleInputChange=this.handleInputChange.bind(this);}handleInputChange(event){consttarget=event.target;constvalue=target.type==='checkbox'?target.checked:target.value;constname=target.name;this.setState({[name]:value});}render(){return();}} 3.22.5. React event ¶
The following example shows how to use the onClick event to modify the data:
React instance ¶
classHelloMessageextendsReact.Component{constructor(props){super(props);this.state={value:'Hello Runoob!'};this.handleChange=this.handleChange.bind(this);}handleChange(event){this.setState({value:'Rookie Tutorial'})}render(){varvalue=this.state.value;return Click me {value}
;}}ReactDOM.render( ,document.getElementById('example')); When you need to update the parent component from the child component state need to create an event handle (handleChange) in the parent component as a prop (updateStateProp) pass it to your subcomponents. Examples are as follows:
React instance ¶
classContentextendsReact.Component{render(){return Click me {this.props.myDataProp}
}}classHelloMessageextendsReact.Component{constructor(props){super(props);this.state={value:'Hello Runoob!'};this.handleChange=this.handleChange.bind(this);}handleChange(event){this.setState({value:'Rookie Tutorial'})}render(){varvalue=this.state.value;return ;}}ReactDOM.render( ,document.getElementById('example'));