我是 native react 的新手。我正在做一个简单的工资计算器组件来练习。我有两个 TextInput 组件,但我似乎无法在其中输入任何内容。这是我的组件的代码:
class SueldoCalc extends Component {
constructor(props)
{
super(props);
}
calcSalario()
{
console.log("Calculating");
}
render()
{
return (
<View>
<Text>Entre las horas trabajadas:</Text>
<TextInput />
<Text>Entre el rate por hora:</Text>
<TextInput />
<TouchableHighlight onPress={this.calcSalario}>
<Text>Calcular salario...</Text>
</TouchableHighlight>
</View>
);
}
}
我尝试订阅 onTextChange 事件,但没有。这太基本了,我在那里找不到任何东西。请帮忙!我在 Android Simulator for Visual Studio 上运行该应用程序。
最佳答案
我在 Android 和 IOS 中都遇到了同样的问题。当我设置宽度和高度如下(注意宽度和高度都必须设置)后,问题解决了:
<TextInput style={{ height: 20, width: 100 }} />
关于react-native - 无法在 React Native TextInput 组件中输入任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39282371/