android - Intl.NumberFormat.formatToParts 不是函数
问题描述
我在React Native中使用 Intl 命名空间来进行一些货币和公制金额格式化(Wh 等)当使用 formatToParts 方法时,在 IOS 和 Android 调试模式下一切正常。但在 Android 开发模式下,我有以下错误:
Intl.NumberFormat(_i18nJs.default.locale,options).formatToParts is not a function. (In 'Intl.NumberFormat(_i18n.Js.default.locale,options).formatToParts(value)','Intl.NumberFormat(_i18nJs.default.locale,options).formatToParts' is undefined)
在发布模式下,我使用此功能的屏幕使应用程序崩溃
代码:
public static formatNumberWithCompacts(value: number, options: FormatNumberOptions = {}): FormatNumberResult {
const isCompactForm =
options.notation === NumberFormatNotationEnum.COMPACT &&
(!options.compactThreshold || (options.compactThreshold && value > options.compactThreshold));
const isCurrency = options.currency && options.style === NumberFormatStyleEnum.CURRENCY;
options.currency = options.currency || I18nManager.currency;
const isUnit = options.unit && options.style === NumberFormatStyleEnum.UNIT;
const isPercent = options.style === NumberFormatStyleEnum.PERCENT;
if (!isCompactForm) {
delete options.notation;
}
// Format the given value with the given options
const parts = Intl.NumberFormat(i18n.locale, options).formatToParts(value);
解决方案
我通过将此处指示的所有 polyfill 导入添加到我的 index.ts 来解决此问题: https ://github.com/web-ridge/react-native-paper-dates/releases/tag/v0.2.15
我还必须按照 Format.js 的文档中的说明预先安装每个 polyfill:https ://formatjs.io/docs/polyfills
推荐阅读
- python-3.x - 无法找出模块的版本
- dialogflow-es - 操作 Dialogflow 意图/实体
- kubernetes-helm - 使 helm 停止跟踪命名空间资源作为发布的一部分,而不实际删除它
- r - object '...' not found in R Functions with lm -->> (Error in eval(predvars, data, env) : object '...' not found)
- c# - winforms未处理异常对话框上的继续按钮行为
- vb6 - VB6 崩溃,运行时错误 5 只有 msgbox
- excel - 不知道如何在另一个宏中运行宏
- java - JTextArea 无法显示 Hashmap 值
- javascript - 强制浏览器重新渲染
- python - re.DOTALL 没有选择换行符