如何在XML视图中从SAPUI5应用程序中的字符串中删除前导零?

Mah*_*ari 0 sapui5

我在SAPDB中有一个整数但由于某种原因它必须存储为NUMERIC,并且数值在SAP DB中存储为字符串.

因此OData服务返回0000000001而不是1.

那么问题是如何在XML视图中删除前导零.问题是我使用XML View时无法使用Javascript进行格式化.

我找到的唯一解决方案是使用这样的代码:

<Text text="{path:'ZId', type:'sap.ui.model.odata.type.ODataType', oConstraints:{isDigitSequence: true}}" />
Run Code Online (Sandbox Code Playgroud)

但我不知道为什么它没有删除前导零,而在其参考文献中已经说过:

if true, the value is handled as a sequence of digits; while formatting leading zeros are removed from the value and while parsing the value is enhanced with leading zeros (if a maxLength constraint is given) or leading zeros are removed from the value (if no maxLength constraint is given); this constraint is supported since 1.35.0. To make this type behave as ABAP type NUMC, use oConstraints.isDigitSequence=true together with oConstraints.maxLength.

我发现一些相关数据的参考文献在以下链接中:

https://archive.sap.com/discussions/thread/3681816

https://openui5.hana.ondemand.com/docs/api/symbols/sap.ui.model.odata.type.String.html

https://openui5.hana.ondemand.com/docs/api/symbols/sap.ui.model.type.Integer.html

https://openui5.hana.ondemand.com/docs/api/symbols/sap.ui.core.format.NumberFormat.html

mat*_*btt 7

您既没有使用正确的类型实现,也没有使用正确的绑定语法来设置约束.请查看文档:

<Text text="{
    path : 'ZId', 
    type : 'sap.ui.model.odata.type.String', 
    constraints: { 
         isDigitSequence : true,
         maxLength : 10
    }
}"/>
Run Code Online (Sandbox Code Playgroud)

  • 我用的图书馆?这是内置功能,旨在用于您的用例,并被数千个应用程序使用. (2认同)