如何在格式化程序中将控件实例设置为“this”?

Vis*_*han 0 sapui5

我正在使用 SAP UI5 1.52。我的格式化程序文件是一个单独的文件并加载到控制器中。但登录this格式化程序会返回视图实例而不是控件实例。

我之前曾提到过这个问题,并尝试使用绝对路径并更改了格式化程序中返回对象的方式。它抛出一个错误,指出找不到函数。

Bog*_*ann 5

用户界面5 1.69+

看法

<MyControl xmlns:core="sap.ui.core" core:require="{ format: 'demo/model/format' }"
  property="{
    path: '...',
    formatter: 'format'
  }"
/><!-- Note: remove the dot (.) in front of the formatter function name -->
Run Code Online (Sandbox Code Playgroud)

格式化程序

sap.ui.define([], function() { // location: "demo/model/format.js"
  "use strict";

  return function(data) {
    // this === control instance
  };
});
Run Code Online (Sandbox Code Playgroud)

从 UI5 1.69 开始,我们可以直接在视图定义中 require 模块。直接在绑定信息中要求和分配格式化程序可以让我们用作this相应的控件实例。

文档中也提到了这一点: