如何将控件引用传递给 XMLView 中的格式化程序? [英] How to pass control reference to formatter in XMLView?

查看:45
本文介绍了如何将控件引用传递给 XMLView 中的格式化程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 SAPUI5 的 JSView 中,很容易将当前控件引用传递给格式化程序函数:

In SAPUI5's JSView, it is quite easy to pass the current control reference to a formatter function:

oTable.bindItems("/rows", new sap.m.ColumnListItem({
    cells : [ new sap.m.Text().bindProperty("text", {
        parts: [
            { path: "someInteger" }
        ],
        formatter: function(iValue) { 
            var idText = this.getId(); //this references the current control
            return iValue;
        }
    })]
}));

(简单"部分当然是因为this在控件的内部格式化函数中被引用了)

(The 'easy' part of course is because this is referenced in the control's inner formatter function)

但是,使用 XMLViews 我还没有设法在格式化程序函数中获得对当前控件的引用:

However, with XMLViews I haven't managed yet to get a reference to the current control in the formatter function:

<Table items="{/rows}">
    <columns>
        <Column>
            <Text text="Some Integer" />
        </Column>
    </columns>
    <items>
        <ColumnListItem>
            <cells>
                <Text text="{ path : 'someInteger', formatter : '.formatCell' }" />
            </cells>
        </ColumnListItem>
    </items>
</Table>

和格式化程序:

formatCell : function (sValue) {
    var a = this; //this references the controller
    return sValue;
}

有人知道如何在 XMLViews 中实现这一点吗?

Anyone knows how to make this work in XMLViews?

推荐答案

在单独的文件中定义格式化程序函数.然后 this 将是其属性正在被格式化的控件.

Define your formatter functions in a separate file. Then this will be the Control whose property is being formatted.

我的/自己的/Formatter.js:

my/own/Formatter.js:

sap.ui.define(function () {
    "use strict";
    return {
        formatCell: function (iValue) {
            var idText = this.getId(); //this references the current control
            return iValue;
        }
    };
});

查看:

<Table items="{/rows}">
    <columns>
        <Column>
            <Text text="Some Integer" />
        </Column>
    </columns>
    <items>
        <ColumnListItem>
            <cells>
                <Text text="{ path : 'someInteger', formatter : 'my.own.Formatter.formatCell' }" />
            </cells>
        </ColumnListItem>
    </items>
</Table>

这篇关于如何将控件引用传递给 XMLView 中的格式化程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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