【发布时间】:2020-08-09 11:07:53
【问题描述】:
我有一个总是必须是数字类型的预渲染值。我将 TextInput 值设置为此数字,但除非我将数字转换为字符串,否则它不会显示在输入字段中。但是,当使用 toString() 或 String(value) 将数字转换为字符串时,通过清除字段来编辑 TextInput 会导致在字段中显示 NaN,由于每次尝试后都会重复出现,因此无法清除。
TextInput 的外观如下:
<TextInput value={5}/>
//displays nothing in the field unless when like this:
<TextInput value="5"/>
<TextInput value={value.toString()}/> and <TextInput value={String(value}/> cause NaN when the field is cleared completely
它也不会发出数字值,但不渲染数字值是更严重的问题。
谁能告诉我如何解决这个问题?
【问题讨论】:
标签: react-native