var addressTxt = new sap.ui.commons.Label({
                id : 'addressTxt',
                text : {
                    parts : [
                             {path : 'Street'},
                             {path : 'PostalCode'},
                             ],
                    formatter : function(Street,PostalCode){
                        var text = "";
                        if(Street)  text = Street+ ",";
                        if(PostalCode) text += PostalCode +","

                        return text;
                    }
                }
                        });

我在这里使用格式化程序函数将两个元素连接到一个文本字段中,但参数的值始终为空。我究竟做错了什么?

最佳答案

给你:http://jsbin.com/openui5-HTML-templates/82/edit?html,output

认为您的主要错误是在没有附加对象和“路径”的情况下构建的部分数组。它直接采用路径。此外,只要路径在模型中是绝对路径,它就需要以“/”开头:

text : {
    parts : [ '/street', '/postalCode' ],
    formatter : function(street, postalCode) {
        var text = "";
        if (street) text = street +",";
        if (postalCode) text += postalCode;
        return text;
    }
}

在此处的文档中找到有关计算字段的更多详细信息:
https://openui5.hana.ondemand.com/#docs/guide/CalcFields.html

关于javascript - SAPUI5 - 格式化程序功能不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19951689/

10-12 13:04
查看更多