如何在 React Native 中找到状态变量的长度?
How to find length of variable in state in react native?
this.state = {
phone: ''
};
我想找到状态变化时 phone 变量的长度,这样如果长度为 10,我就可以执行操作。
此外,如果可能,您能否让我知道如何在 React Native 中以编程方式启用和禁用本机基础按钮。
我是 React Native 的初学者
获取字符串的长度
如果把phone这个数字保存为字符串就很简单了。你可以做
let phoneNumberLength = this.state.phone.length
然后你可以在 if 语句中使用它
if (phoneNumberLength === 10) {
// do something here
}
原生基地
nativebase 中的 Button 组件有一个 disabled 属性,您可以使用它。 http://docs.nativebase.io/Components.html#button-disabled-headref
您可以在您的状态中设置一个值来控制按钮是否被禁用。调用 this.state({buttonDisabled: true})
将禁用按钮
this.state {
buttonDisabled: false
}
<Button disabled={this.state.buttonDisabled} />
this.state = {
phone: ''
};
我想找到状态变化时 phone 变量的长度,这样如果长度为 10,我就可以执行操作。
此外,如果可能,您能否让我知道如何在 React Native 中以编程方式启用和禁用本机基础按钮。
我是 React Native 的初学者
获取字符串的长度
如果把phone这个数字保存为字符串就很简单了。你可以做
let phoneNumberLength = this.state.phone.length
然后你可以在 if 语句中使用它
if (phoneNumberLength === 10) {
// do something here
}
原生基地
nativebase 中的 Button 组件有一个 disabled 属性,您可以使用它。 http://docs.nativebase.io/Components.html#button-disabled-headref
您可以在您的状态中设置一个值来控制按钮是否被禁用。调用 this.state({buttonDisabled: true})
将禁用按钮
this.state {
buttonDisabled: false
}
<Button disabled={this.state.buttonDisabled} />