共计 1433 个字符,预计需要花费 4 分钟才能阅读完成。
依照 Jerry 这篇文章介绍的代码,运行之后,给类型为 sap.ui.model.type.Currency
的字段设置一个非 number
类型的值之后,触发该数据类型自带的数据校验机制,显示 Enter a number
的谬误音讯。
SAP UI5 利用开发教程之四十六 – 应用 Message Manager 实现开箱即用的验证 (Validation) 信息抛出
调试入口在 CompositeBinding.prototype.setExternalValue
函数外部。
if (this.oType) {pValues = SyncPromise.resolve().then(function() {
var aCurrentValues;
if (that.oType.getParseWithValues()) {aCurrentValues = that.getCurrentValues();
}
return that.oType.parseValue(oValue, that.sInternalType, aCurrentValues);
outputFormat 的具体实现是 NumberFormat
:
NumberFormat 是一个动态类,用于依据一组格局选项格式化和解析数值。
数据格式化是 SAPUI5 中的要害性能之一,它使应用程序可能依据用户区域设置显示数据。为此,SAPUI5 应用通用区域设置数据存储库 (CLDR),这是一个提供特定区域设置模式的第三方库。SAPUI5 应用这些模式来适应不同语言的约定。
数据格式化的一种用例是格式化和解析数字(包含货币信息)的能力。对于这个特定的用例,CLDR 提供带有预配置货币信息的模式,例如一组不同货币的小数位数。也能够通过增加新的自定义货币或重新配置现有货币来定义自定义货币。
其中匹配整形数值的正则表达式,保护在变量 sRegExpInt
内:^\s*([\+\+⁺₊➕﬩﹢+\-\-‐‒–⁻₋−➖﹣-]?[0-9,]+)\s*$
正则表达式验证失败:
因而抛出 ParserException
异样:
从 library resource bundle 里获得占位符 EnterNumber
的文本:Enter a number
:
对于 NumberFormat 更多的例子:
// "NumberFormat" required from module "sap/ui/core/format/NumberFormat"
var oCurrencyFormat = NumberFormat.getCurrencyInstance({currencyCode: false});
oCurrencyFormat.format(1234.567, "USD"); // returns $1,234.57
oCurrencyFormat.format(1234.567, "JPY"); // returns ¥1,235
oCurrencyFormat.parse("$1,234.57"); // returns [1234.57, "USD"]
oCurrencyFormat.parse("¥1,235"); // returns [1235, "JPY"]
货币格局的以下格局选项可用:
- currencyCode 定义当 showMeasure 设置为 true 时是否应用代码或符号。
- trailingCurrencyCode 定义货币代码是否始终显示在金额之后,与区域设置无关。
- currencyContext 定义了用于格式化货币编号的模式。它能够设置为规范(默认)或会计。