sap.m.Input sap ui5 中的自定义输入类型 [英] custom input type in sap.m.Input sap ui5

查看:39
本文介绍了sap.m.Input sap ui5 中的自定义输入类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个输入字段 (sap.m.Input),我需要它的类型为 Float.我尝试使用 sap.ui.model.type.Float() 但它没有用.

I have a input field (sap.m.Input) for which I need the type as Float. I tried using the sap.ui.model.type.Float() but it did not work.

如何为我的输入字段使用自定义类型.我没有任何绑定,只需要将输入字段的类型设置为浮动.举个例子会很有帮助.

How can I use a custom type for my input field. I don't have any binding, just need to set the type of the input field as float. An example would be really helpful.

提前致谢,迪帕克

推荐答案

我也有同样的问题,新的 sap.ui.model.type.Float 的用法似乎是从 OData 服务转换字符串(Edm.Decimal) 转换为实数浮点数.这将有助于显示正确的数字,但如果您尝试将更改后的值写回(OData 双向绑定),则无效.

I have the same problem, usage of new sap.ui.model.type.Float seems to convert the string from OData service (Edm.Decimal) into a real float number. This will work for showing the number correct, but not if you try to write a changed value back (OData two-way-binding).

因此我实现了一个自己的类型:

Therefore I implemented an own type like this:

jQuery.sap.declare("my.package.MyFloat");
sap.ui.model.SimpleType.extend("my.package.MyFloat", {
    formatValue : function(oValue) {
        return oValue;
    },

    parseValue : function(oValue) {
        return oValue;
    },

    validateValue : function(oValue) {
        if (oValue != null && oValue != "" && oValue != undefined) {
            if (isNaN(Number(oValue))) {
                var messageString = sap.ui.getCore().getModel("i18n").getResourceBundle().getText("KEY_TO_ERROR_MESSAGE");
                throw new sap.ui.model.ValidateException(messageString);
            }
        }
    }
})

我在这里检测到一个 SAP 示例:http://help.sap.com/saphelp_nw74/helpdata/de/91/f0652b6f4d1014b6dd926db0e91070/content.htm在文件中搜索 PLZ.

I detected one SAP example here: http://help.sap.com/saphelp_nw74/helpdata/de/91/f0652b6f4d1014b6dd926db0e91070/content.htm search for PLZ in the file.

目前我正在寻找一种在MyFloat的构建过程中添加一些参数的方法.

Currently I am searching for a way to add some parameters during the construction of MyFloat.

你可以这样使用这样的类型:

You can use such a type this way:

new sap.m.Input({
     value: {
         path : "BindingPathToAttribute",
         type : new my.package.MyFloat({})
     }
}),

这篇关于sap.m.Input sap ui5 中的自定义输入类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆