我在React Native中有一个TextInput AlertIOS:
AlertIOS.prompt(
'Enter password',
'Enter your password to claim your $1.5B in lottery winnings',
[
{
text: 'Cancel',
onPress: () => console.log('Cancel Pressed'),
style: 'cancel',
},
{
text: 'OK',
onPress: (password) => password.trim() != "" ? Dismiss ALERT : KEEP ALERT,
},
],
'secure-text',
);
有没有办法仅以编程方式关闭警报?即当单击非取消选项时,我只想在条件满足时关闭警报。
这可能吗?
答案 0 :(得分:-1)
如果您想在点击Cancel
按钮时解除警报,则可以使用像onPress: () => {}
这样的空函数代替console.log()
。
如果您希望在条件满足时解除警报,可以尝试以下操作:
onPress: (password) => password.trim() !== "" ? this.doSomething() : this.doAnotherStuff();
或
onPress: (password) => password.trim() !== "" ? this.doSomething() : () => {};