react-native - 反应本机文本输入从另一个文本输入中获取值
问题描述
当我在textInput 商品编号中输入商品数量时,我希望商品的价格自动出现在textIinput Price中。这是我的快速脚本,它不起作用
请帮我改进,谢谢
constructor(props){
super(props);
this.state={
qty: 0,
prc: 0,
}
}
price = () =>{
var price = this.state.qty * 250;
this.setState({
prc: price,
})
}
render(){
return (
<View style={styles.container}>
.....
<View style={{...}}>
<Text style={{...}}>Item number :</Text>
<TextInput
...
onChangeText={(entry) => {
this.setState({qty: entry})
this.price();
}}
...
/>
</View>
<View style={{...}}>
<Text style={{...}}>Price :</Text>
<TextInput
....
value={this.state.prc}
onChangeText={(entry) => {
this.setState({prc: entry})
}}
....
/>
</View>
</View>
解决方案
import React, { Component, useState } from 'react';
从'react-native'导入{视图,文本,文本输入};
导出默认示例 = () => {
const [price, setprice] = useState(0);
return (
<View>
<Text>Item number :</Text>
<TextInput
onChangeText={(entry) => setprice(entry)}
/>
<Text>Price :</Text>
<TextInput defaultValue={(parseInt(price) * 250).toString()}></TextInput>
</View>
);
}
推荐阅读
- python - tweepy 没有给我最后一条推文
- angular - 无法使用 Angular 切换到另一个页面
- wordpress - 我想在 wordpress 的 Slider 下添加号召性用语按钮
- css - 网站在 windows/android 和苹果生态系统中的不同输出
- python - 更改 pyttsx3 语言
- android - 在android中进行BLE扫描后收到不正确的结果
- gatsby - 将 Tailwind 加载到 Gatsby 站点时延迟 300 毫秒
- python - 在 Python 3.8 中导入 tensorflow 时出错
- jmeter - 如何在 Azure-Event-Hub/(或任何 DB)中批量写入 JMeter 结果
- javascript - 从 Object 键调用方法