- 浏览: 2539699 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
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 232MongoDB 2019(3)Security and Aut ... -
Memory Leak in NodeJS
2018-12-20 06:26 723Memory Leak in NodeJS I have d ... -
Remote Desktop Client
2018-12-07 13:19 1186Remote Desktop Client There is ... -
MetaBase UI Console(2)Docker on MySQL
2018-11-29 06:58 939MetaBase UI Console(2)Docker on ... -
AWS Lambda and Serverless Timeout
2018-09-20 01:20 625AWS Lambda and Serverless Timeo ... -
2018 WebSocket(1)Introduction
2018-03-20 01:22 11032018 WebSocket(1)Introduction ... -
2018 TypeScript Update(3)Introduction Basic Grammar
2018-03-08 03:08 6002018 TypeScript Update(3)Introd ... -
2018 TypeScript Update(2)Introduction Basic Grammar - Classes and Functions
2018-03-06 05:32 5512018 TypeScript Update(2)Introd ... -
2018 TypeScript Update(1)Introduction Basic Grammar - Types and Interface
2018-03-03 01:15 5992018 TypeScript Update(1)Introd ... -
Charts and Console(6)Paging
2018-03-01 00:12 577Charts and Console(6)Paging Th ... -
Vue.JS(3)Google Login
2018-02-14 04:53 1296Vue.JS(3)Google Login I just p ... -
Vue.JS(2)Monitor Water Console - ChartJS and Axios
2018-02-14 03:17 718Vue.JS(2)Monitor Water Console ... -
Vue.JS(1)Introduction and Basic Demo
2018-02-08 06:47 604Vue.JS(1)Introduction and Basic ... -
Charts and Console(5)Validation Form
2017-10-03 05:12 804Charts and Console(5)Validation ... -
Charts and Console(4)Display and Enhancement
2017-09-20 05:39 631Charts and Console(4)Display an ... -
Charts and Console(3)Auth and Login
2017-09-13 03:45 659Charts and Console(3)Auth and L ... -
Charts and Console(2)Login and Proxy
2017-08-31 05:39 874Charts and Console(2)Login and ... -
Charts and Console(1)UI Console and RESTful Client
2017-08-29 11:02 766Charts and Console(1)UI Console ... -
Blog Project(2)Express Backend API - istanbul - mocha - bunyan
2017-06-09 00:05 473Blog Project(2)Express Backend ... -
ReactJS(5)Composition vs Inheritance
2017-06-06 05:55 1106ReactJS(5)Composition vs Inheri ...
相关推荐
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 {
4. **状态管理**:根据挑战的复杂性,可能会涉及到状态提升(lifting state up)或者使用像Redux这样的状态管理库来协调组件间的数据流。 5. **React Hooks**:React 16.8引入了Hooks,如`useState`,`useEffect`,...
标题中的“image_compress.rar”可能是一个包含图像压缩代码或程序的RAR压缩文件,而关键词“lifting”,“lifting wavelet”,“wavelet lifting”以及“小波分解”则指明了这个压缩包的内容与小波变换的提升算法...
### 快速提升小波变换(Fast Lifting Wavelet Transform) #### 概述 快速提升小波变换(Fast Lifting Wavelet Transform, FLWT)是一种高效的小波变换算法,它在1999年至2004年间由C. Valens提出并不断完善。这种...
7. 状态提升(Lifting State Up):如果多个组件需要共享相同的状态,可以将这个状态提升到它们的共同父组件。在汉堡构建器中,可能需要在父组件中管理所有配料的选择状态。 8. 状态初始化(State Initialization)...
标题与描述均提到了“小波变换(Wavelets)”与“提升方案(Lifting Scheme)”,这是一篇关于介绍小波变换中的提升方案的文章。文章由Wim Sweldens撰写,旨在提供一个简短而深入的提升方案导览,并讨论其在构建小波...
6. **状态提升(Lifting State Up)**:当多个组件需要共享状态时,通常会将状态提升到它们的共同父组件中,通过props将状态传递下去。 7. **受控组件与非受控组件**:在表单处理中,React提供两种方式管理表单数据...
5-3lifting 代码 dsw vc
Adjustable lifting table.emmx
8. **状态提升(Lifting State Up)**:当多个组件需要共享状态时,将状态移至最近的共同父组件,以避免数据冗余和同步问题。 9. **优化技术**:React提供了多种性能优化手段,如PureComponent、...
propeller design with lifting line theory
it program resolves the lifting line theory for lift estimation in 3D
标题中的“tishengfa-pragram.rar_lifting_提升小波”表明这是一个关于提升小波变换的程序包,其中“tishengfa-pragram.rar”可能是程序的压缩文件名,而“lifting”和“提升小波”是关键词,强调了这个程序的核心...
提升小波变换程序, %LWT Lifting wavelet decomposition 1-D. % LWT performs a 1-D lifting wavelet decomposition % with respect to a particular lifted wavelet that you specify.
标题中的“tishengxiaobo.zip_lifting_去噪_小波去噪_提升_提升小波去噪”表明这是一个关于提升小波去噪技术的压缩文件,其中可能包含源代码、教程或示例程序。描述提到这是第二代提升小波去噪程序,暗示其在去噪...
线性二代小波,也称为提升小波(Lifting Scheme),是小波分析领域中的一个重要概念,它提供了一种高效且灵活的实现离散小波变换的方法。与传统的滤波器组方法相比,提升方案在计算效率和内存使用上具有优势,特别...
4. **双精度计算**:双精度浮点数提供了更高的数值精度,通常在需要更高精确度的科学计算中使用。 5. **应用文档**:用户可能通过提供的应用文档了解如何使用LIFTPACK进行实际问题的解决,包括理论背景、操作指南和...
"lifting up"通常指提起物体,"bringing up"有抚养或提出的意思,而"growing up"则指成长。 6. 名词辨析:in a poor state of health是一个固定搭配,意为“健康状况不佳”,state在这里指的是人的健康状态。 7. ...
基于Lifting小波变换原理对细分曲面实体切片操作产生的离散交点序列进行...用4种不同的Lifting小波变换进行了多分辨率曲线的构造实验,并对产生的多分辨率曲线进行了对比,讨论分析了这些Lifting变换方法的性能特点。