我不明白 promptValue 是如何存储的。 我有以下函数,我想将 promptValue 传递给回调函数“this.rename”。我不知道如何获得这个值。 react native people 发布的示例正在做一些神秘的事情来获得这个值。谁能解释一下吗?
renamePrompt: function(line) {
AlertIOS.prompt(
'Rename',
line.name,
this.rename
);
},
最佳答案
AlertIOS.prompt
接受几个参数。让我们来看看它们:
AlertIOS.prompt(
'Title', 'Default Value',
[{text: 'Button One', onPress: this.firstButtonPress.bind(this)},
{text: 'Button Two', onPress: this.secondButtonPress.bind(this)}]
)
AlertIOS.prompt
接受的第一个参数是 title
——向用户显示的内容。这是必需的 propType
。
下一个参数是一个值
,它是为用户预先填充到文本框中的内容。这是一个可选 propType
。
之后,您看到的数组映射到用户可以点击的按钮。这些按钮表示为带有一些键/值对的对象。第一个是 text
,它将显示按钮文本。第二个是 onPress
,这是您指定用于处理按下的特定按钮的方法。
为了检索按钮的值,您需要将 this
(在本例中为提示)绑定(bind)到您的 onPress
方法。如果这样做,您可以让 onPress
处理程序访问键入的值,如下所示:
firstButtonPress(value) {
console.log(value)
}
此按钮数组有条件可选。如果您选择不提供按钮列表,AlertIOS 将要求您传入回调函数作为 AlertIOS.prompt
的参数(但不能同时提供一组按钮和回调)。
关于ios - 如何获取AlertIOS.prompt的promptValue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31431469/