- 浏览: 2490444 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
ReactJS(4)Forms Lifting State Up
Forms
https://facebook.github.io/react/docs/forms.html
Controlled Components
class NameForm extends React.Component {
constructor(props) {
super(props);
this.state = {value: ‘'};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
this.setState({value: event.target.value});
}
handleSubmit(event) {
alert('A name was submitted: ' + this.state.value);
event.preventDefault();
}
render() {
return ( <form onSubmit={this.handleSubmit}>
<label> Name: <input type="text" value={this.state.value} onChange={this.handleChange} /> </label>
<input type="submit" value="Submit" />
</form> );
}
}
The textarea Tag
In ReactJS textarea use value.
<textarea value={this.state.value} onChange={this.handleChange} />
The select Tag
Instead of using this selected attribute, reactJS uses a value attribute on the root select tag.
<select value={this.state.value} onChange={this.handleChange}>
<option value=“greapefruit”>Grapefruit</option>
<option value=“lime”>Lime</option>
<option value=“coconut>Coconut</option>
<option value=“mango”>Mango</option>
</select>
Handling Multiple Inputs
Put name on the state value, it is name value pair.
class Reservation extends React.Component {
constructor(props) {
super(props);
this.state = {
isGoing: true,
numberOfGuests: 2
};
this.handleInputChange = this.handleInputChange.bind(this);
}
handleInputChange(event) {
const target = event.target;
const value = target.type === 'checkbox' ? target.checked : target.value;
const name = target.name;
this.setState({
[name]: value
});
}
render() {
return (
<form>
<label>
Is going:
<input
name="isGoing"
type="checkbox"
checked={this.state.isGoing}
onChange={this.handleInputChange} />
</label>
<br />
<label>
Number of guests:
<input
name="numberOfGuests"
type="number"
value={this.state.numberOfGuests}
onChange={this.handleInputChange} />
</label>
</form>
);
}
}
ReactDOM.render(
<Reservation />,
document.getElementById('root')
);
Lifting State Up
https://facebook.github.io/react/docs/lifting-state-up.html
function BoilingVerdict(props) {
if (props.celsius >= 100) {
return <p>The water would boil.</p>;
}
return <p>The water would not boil.</p>;
}
class Calculator extends React.Component {
constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this);
this.state = {temperature: ''};
}
handleChange(e) {
this.setState({temperature: e.target.value});
}
render() {
const temperature = this.state.temperature;
return (
<fieldset>
<legend>Enter temperature in Celsius:</legend>
<input
value={temperature}
onChange={this.handleChange} />
<BoilingVerdict
celsius={parseFloat(temperature)} />
</fieldset>
);
}
}
ReactDOM.render(
<Calculator />,
document.getElementById('root')
);
One input changes will affect the display of another component.
Adding a Second Input
c —> Celsius
f —> Fahrenheit
Writing Conversion Functions
function toCelsius(fahrenheit){
return (fahrenheit - 32) * 5 / 9 ;
}
function toFahrenheit(celsius){
return (celsius * 9 / 5) + 32;
}
function tryConvert(temperature, convert){
const input = parseFloat(temperature);
if(Number.isNaN(input)){
return ‘';
}
const output = convert(input);
const rounded = Math.round(output * 1000) /1000;
return rounded.toString();
}
tryConvert('abc', toCelsius) — “”
tryConvert('10.22', toFahrenheit) — “50.296”
const scaleNames = {
c: 'Celsius',
f: 'Fahrenheit'
};
function toCelsius(fahrenheit) {
return (fahrenheit - 32) * 5 / 9;
}
function toFahrenheit(celsius) {
return (celsius * 9 / 5) + 32;
}
function tryConvert(temperature, convert) {
const input = parseFloat(temperature);
if (Number.isNaN(input)) {
return '';
}
const output = convert(input);
const rounded = Math.round(output * 1000) / 1000;
return rounded.toString();
}
function BoilingVerdict(props) {
if (props.celsius >= 100) {
return <p>The water would boil.</p>;
}
return <p>The water would not boil.</p>;
}
class TemperatureInput extends React.Component {
constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this);
}
handleChange(e) {
this.props.onTemperatureChange(e.target.value);
}
render() {
const temperature = this.props.temperature;
const scale = this.props.scale;
return (
<fieldset>
<legend>Enter temperature in {scaleNames[scale]}:</legend>
<input value={temperature}
onChange={this.handleChange} />
</fieldset>
);
}
}
class Calculator extends React.Component {
constructor(props) {
super(props);
this.handleCelsiusChange = this.handleCelsiusChange.bind(this);
this.handleFahrenheitChange = this.handleFahrenheitChange.bind(this);
this.state = {temperature: '', scale: 'c'};
}
handleCelsiusChange(temperature) {
this.setState({scale: 'c', temperature});
}
handleFahrenheitChange(temperature) {
this.setState({scale: 'f', temperature});
}
render() {
const scale = this.state.scale;
const temperature = this.state.temperature;
const celsius = scale === 'f' ? tryConvert(temperature, toCelsius) : temperature;
const fahrenheit = scale === 'c' ? tryConvert(temperature, toFahrenheit) : temperature;
return (
<div>
<TemperatureInput
scale="c"
temperature={celsius}
onTemperatureChange={this.handleCelsiusChange} />
<TemperatureInput
scale="f"
temperature={fahrenheit}
onTemperatureChange={this.handleFahrenheitChange} />
<BoilingVerdict
celsius={parseFloat(celsius)} />
</div>
);
}
}
ReactDOM.render(
<Calculator />,
document.getElementById('root')
);
References:
https://facebook.github.io/react/docs/forms.html
Forms
https://facebook.github.io/react/docs/forms.html
Controlled Components
class NameForm extends React.Component {
constructor(props) {
super(props);
this.state = {value: ‘'};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
this.setState({value: event.target.value});
}
handleSubmit(event) {
alert('A name was submitted: ' + this.state.value);
event.preventDefault();
}
render() {
return ( <form onSubmit={this.handleSubmit}>
<label> Name: <input type="text" value={this.state.value} onChange={this.handleChange} /> </label>
<input type="submit" value="Submit" />
</form> );
}
}
The textarea Tag
In ReactJS textarea use value.
<textarea value={this.state.value} onChange={this.handleChange} />
The select Tag
Instead of using this selected attribute, reactJS uses a value attribute on the root select tag.
<select value={this.state.value} onChange={this.handleChange}>
<option value=“greapefruit”>Grapefruit</option>
<option value=“lime”>Lime</option>
<option value=“coconut>Coconut</option>
<option value=“mango”>Mango</option>
</select>
Handling Multiple Inputs
Put name on the state value, it is name value pair.
class Reservation extends React.Component {
constructor(props) {
super(props);
this.state = {
isGoing: true,
numberOfGuests: 2
};
this.handleInputChange = this.handleInputChange.bind(this);
}
handleInputChange(event) {
const target = event.target;
const value = target.type === 'checkbox' ? target.checked : target.value;
const name = target.name;
this.setState({
[name]: value
});
}
render() {
return (
<form>
<label>
Is going:
<input
name="isGoing"
type="checkbox"
checked={this.state.isGoing}
onChange={this.handleInputChange} />
</label>
<br />
<label>
Number of guests:
<input
name="numberOfGuests"
type="number"
value={this.state.numberOfGuests}
onChange={this.handleInputChange} />
</label>
</form>
);
}
}
ReactDOM.render(
<Reservation />,
document.getElementById('root')
);
Lifting State Up
https://facebook.github.io/react/docs/lifting-state-up.html
function BoilingVerdict(props) {
if (props.celsius >= 100) {
return <p>The water would boil.</p>;
}
return <p>The water would not boil.</p>;
}
class Calculator extends React.Component {
constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this);
this.state = {temperature: ''};
}
handleChange(e) {
this.setState({temperature: e.target.value});
}
render() {
const temperature = this.state.temperature;
return (
<fieldset>
<legend>Enter temperature in Celsius:</legend>
<input
value={temperature}
onChange={this.handleChange} />
<BoilingVerdict
celsius={parseFloat(temperature)} />
</fieldset>
);
}
}
ReactDOM.render(
<Calculator />,
document.getElementById('root')
);
One input changes will affect the display of another component.
Adding a Second Input
c —> Celsius
f —> Fahrenheit
Writing Conversion Functions
function toCelsius(fahrenheit){
return (fahrenheit - 32) * 5 / 9 ;
}
function toFahrenheit(celsius){
return (celsius * 9 / 5) + 32;
}
function tryConvert(temperature, convert){
const input = parseFloat(temperature);
if(Number.isNaN(input)){
return ‘';
}
const output = convert(input);
const rounded = Math.round(output * 1000) /1000;
return rounded.toString();
}
tryConvert('abc', toCelsius) — “”
tryConvert('10.22', toFahrenheit) — “50.296”
const scaleNames = {
c: 'Celsius',
f: 'Fahrenheit'
};
function toCelsius(fahrenheit) {
return (fahrenheit - 32) * 5 / 9;
}
function toFahrenheit(celsius) {
return (celsius * 9 / 5) + 32;
}
function tryConvert(temperature, convert) {
const input = parseFloat(temperature);
if (Number.isNaN(input)) {
return '';
}
const output = convert(input);
const rounded = Math.round(output * 1000) / 1000;
return rounded.toString();
}
function BoilingVerdict(props) {
if (props.celsius >= 100) {
return <p>The water would boil.</p>;
}
return <p>The water would not boil.</p>;
}
class TemperatureInput extends React.Component {
constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this);
}
handleChange(e) {
this.props.onTemperatureChange(e.target.value);
}
render() {
const temperature = this.props.temperature;
const scale = this.props.scale;
return (
<fieldset>
<legend>Enter temperature in {scaleNames[scale]}:</legend>
<input value={temperature}
onChange={this.handleChange} />
</fieldset>
);
}
}
class Calculator extends React.Component {
constructor(props) {
super(props);
this.handleCelsiusChange = this.handleCelsiusChange.bind(this);
this.handleFahrenheitChange = this.handleFahrenheitChange.bind(this);
this.state = {temperature: '', scale: 'c'};
}
handleCelsiusChange(temperature) {
this.setState({scale: 'c', temperature});
}
handleFahrenheitChange(temperature) {
this.setState({scale: 'f', temperature});
}
render() {
const scale = this.state.scale;
const temperature = this.state.temperature;
const celsius = scale === 'f' ? tryConvert(temperature, toCelsius) : temperature;
const fahrenheit = scale === 'c' ? tryConvert(temperature, toFahrenheit) : temperature;
return (
<div>
<TemperatureInput
scale="c"
temperature={celsius}
onTemperatureChange={this.handleCelsiusChange} />
<TemperatureInput
scale="f"
temperature={fahrenheit}
onTemperatureChange={this.handleFahrenheitChange} />
<BoilingVerdict
celsius={parseFloat(celsius)} />
</div>
);
}
}
ReactDOM.render(
<Calculator />,
document.getElementById('root')
);
References:
https://facebook.github.io/react/docs/forms.html
发表评论
-
MongoDB 2019(3)Security and Auth
2019-11-16 06:48 205MongoDB 2019(3)Security and Aut ... -
Memory Leak in NodeJS
2018-12-20 06:26 693Memory Leak in NodeJS I have d ... -
Remote Desktop Client
2018-12-07 13:19 1152Remote Desktop Client There is ... -
MetaBase UI Console(2)Docker on MySQL
2018-11-29 06:58 903MetaBase UI Console(2)Docker on ... -
AWS Lambda and Serverless Timeout
2018-09-20 01:20 599AWS Lambda and Serverless Timeo ... -
2018 WebSocket(1)Introduction
2018-03-20 01:22 10752018 WebSocket(1)Introduction ... -
2018 TypeScript Update(3)Introduction Basic Grammar
2018-03-08 03:08 5702018 TypeScript Update(3)Introd ... -
2018 TypeScript Update(2)Introduction Basic Grammar - Classes and Functions
2018-03-06 05:32 5212018 TypeScript Update(2)Introd ... -
2018 TypeScript Update(1)Introduction Basic Grammar - Types and Interface
2018-03-03 01:15 5702018 TypeScript Update(1)Introd ... -
Charts and Console(6)Paging
2018-03-01 00:12 557Charts and Console(6)Paging Th ... -
Vue.JS(3)Google Login
2018-02-14 04:53 1243Vue.JS(3)Google Login I just p ... -
Vue.JS(2)Monitor Water Console - ChartJS and Axios
2018-02-14 03:17 692Vue.JS(2)Monitor Water Console ... -
Vue.JS(1)Introduction and Basic Demo
2018-02-08 06:47 575Vue.JS(1)Introduction and Basic ... -
Charts and Console(5)Validation Form
2017-10-03 05:12 773Charts and Console(5)Validation ... -
Charts and Console(4)Display and Enhancement
2017-09-20 05:39 604Charts and Console(4)Display an ... -
Charts and Console(3)Auth and Login
2017-09-13 03:45 629Charts and Console(3)Auth and L ... -
Charts and Console(2)Login and Proxy
2017-08-31 05:39 845Charts and Console(2)Login and ... -
Charts and Console(1)UI Console and RESTful Client
2017-08-29 11:02 737Charts and Console(1)UI Console ... -
Blog Project(2)Express Backend API - istanbul - mocha - bunyan
2017-06-09 00:05 447Blog Project(2)Express Backend ... -
ReactJS(5)Composition vs Inheritance
2017-06-06 05:55 1076ReactJS(5)Composition vs Inheri ...
相关推荐
Wavelets and the Lifting Scheme A 5 Minute Tour
this s the sourcecode of lifting scheme
React分派器 ... No need in "Lifting state up" */ function reducer ( state , { type } ) { switch ( type ) { case 'INC' : return { count : state . count + 1 } ; case 'DEC' : return {
the fast lifting wavelet transform (权威英文原版)
5-3lifting 代码 dsw vc
Adjustable lifting table.emmx
该程序实例首先对二维图像进行提升小波分解,然后构造传统小波分解结构[c,s],接着使用函数ddencmp()获取信号压缩阈值,再采用函数wdencmp()实现图像压缩
propeller design with lifting line theory
it program resolves the lifting line theory for lift estimation in 3D
提升小波变换程序, %LWT Lifting wavelet decomposition 1-D. % LWT performs a 1-D lifting wavelet decomposition % with respect to a particular lifted wavelet that you specify.
LIFTPACK: A Software Package for Wavelet Transforms using Lifting 文档(3):应用
基于Lifting小波变换原理对细分曲面实体切片操作产生的离散交点序列进行...用4种不同的Lifting小波变换进行了多分辨率曲线的构造实验,并对产生的多分辨率曲线进行了对比,讨论分析了这些Lifting变换方法的性能特点。
您应该出于以下两个原因考虑使用reactjs-popup: :check_mark_button: 模态,工具提示,菜单:全库合一 :person_lifting_weights: :check_mark_button: 很小的库(3kb) :high_voltage: :check_mark_button: 完全可...
Create React App入门该项目是通过引导的。可用脚本在项目目录中,可以运行:yarn start 在开发模式下运行应用程序。 打开在浏览器中查看它。 如果您进行编辑,则页面将重新加载。 您还将在控制台中看到任何棉绒错误...
De-noising of Damage Signal in Wire Rope Based on Adaptive Lifting Wavelet,战卫侠,谭继文,At the basis of the adaptive lifting wavelet transform, a method was proposed for solving the problem of ...
线性二代小波分解的代码可以参考一下,供信号处理及图像处理方面的学习应用
React岭状态 :woman_lifting_weights: :high_voltage: :man_lifting_weights: 简单的 :flexed_biceps: 快速地 :high_voltage: 和小 :balloon: (400字节)React的全局状态管理,它也可以在React组件之外使用!...
本程序实现任意偶数大小图像第二代双正交提升小波变换.可用。
nd_lifting 数据库项目
2代小波示意程序 2维小波变换经典程序 Daubechies小波基的构造 采用多孔trous算法(undecimated wavelet transform)实现小波变换 平移变换平移法(cycle_spinning)消除gibbs效应 提升法97经典程序 ...