未调用 SAPUI5 格式化程序 [英] SAPUI5 Formatter is not called

查看:48
本文介绍了未调用 SAPUI5 格式化程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试调用格式化程序.例如将文本转换为大写.我有两个格式化程序,一个在控制器中,一个在 utils 文件夹中.

I am trying to call a the formatter. e.g. to transform a text to uppercase. I have two formatters, one is in the controller and one is globally in the utils folder.

我试图调用两者,但没有调用.有人可以帮我吗:(?

i tried to call both, but none is called. Can someone help me please :(?

我在 utils 文件夹中有一个全局格式化程序:

I have a global formatter in utils folder:

jQuery.sap.declare("my.app.util.Formatter");
my.app.util.Formatter = {

    toUpperCase: function(sStr) {
        return sStr.toUpperCase();
    }

};

和我的控制器中的一个格式化程序(我也执行 require $.sap.require("my.app.util.Formatter"); ):

and one formatter in my controller (i do the require $.sap.require("my.app.util.Formatter"); as well):

myControllerToUpperCaseFormatter : function(sStr) {
  console.log('I WILL DO NOTHING!');
  return sStr.toUpperCase();
}

我的 XML:

<mvc:View controllerName="my.app.view.XXX"
xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns:l="sap.ui.layout"
xmlns:f="sap.ui.layout.form" xmlns:c="sap.ui.core" xmlns="sap.m">
<Page class="sapUiFioriObjectPage" title="Test">
    <content>

        <Button text="{path: 'MyModel>/name', formatter: 'my.app.util.Formatter.toUpperCase'}"></Button>

        <Button text="{path: 'MyModel>/name', formatter: '.myControllerToUpperCaseFormatter' }"></Button>

    </content>
</Page>

感谢您的帮助!

推荐答案

您的绑定看起来不正确

MyModel>/name//它声明 name 是数据属性层次结构根部的一个属性.正确的方法:

MyModel>/name // it states that name is a property at the root of the data property hierarchy. Right Way:

<Button text="{path: 'MyModel>name', formatter: '.myControllerToUpperCaseFormatter' }"></Button>

尽管如此,我有时也遇到过这个问题!

Nevertheless, I too sometimes have faced this issue!

出于某种原因,当使用两个或更多参数时,它开始工作.

For some reason, when two or more parameters are used it started working.

示例:

<Button text="{parts:[{path:'MyModel>name'},{path:'MyModel>somethingElse'}],formatter: '.myControllerToUpperCaseFormatter' }"></Button>

其他解决方案:

看起来您正在绑定来自 UI 控制器的数据.如果是,请格式化您想要的数据,然后将其设置为模型.

Looks like you are binding the data from UI controller. If yes, format the data you want and then set it to model.

这篇关于未调用 SAPUI5 格式化程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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