javascript SAPUI5 - 格式化程序功能不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19951689/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SAPUI5 - formatter function not working
提问by Themasterhimself
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;
}
}
});
I am using the the formatter function to concatenate two elements in to a text field here, how ever the values for the parameters are always null. What am I doing wrong?
我在这里使用格式化程序函数将两个元素连接到一个文本字段中,但参数的值始终为空。我究竟做错了什么?
回答by cschuff
Here you go: http://jsbin.com/openui5-HTML-templates/82/edit?html,output
给你:http: //jsbin.com/openui5-HTML-templates/82/edit?html,output
Think your main mistake was the parts array that is build without additional objects and 'path'. It directly takes the paths. Furthermore as long as the path is absolute inside of your model it needs to start with '/':
认为您的主要错误是在没有附加对象和“路径”的情况下构建的部分数组。它直接采用路径。此外,只要路径在模型中是绝对路径,它就需要以“/”开头:
text : {
parts : [ '/street', '/postalCode' ],
formatter : function(street, postalCode) {
var text = "";
if (street) text = street +",";
if (postalCode) text += postalCode;
return text;
}
}
Find some more details on calculated fields in the docs here: https://openui5.hana.ondemand.com/#docs/guide/CalcFields.html
在此处的文档中找到有关计算字段的更多详细信息:https: //openui5.hana.ondemand.com/#docs/guide/CalcFields.html