最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - SAPUI5 - formatter function not working - Stack Overflow

programmeradmin0浏览0评论
  var addressTxt = new sap.uimons.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?

  var addressTxt = new sap.ui.mons.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?

Share Improve this question edited Aug 11, 2016 at 19:29 cschuff 5,5427 gold badges37 silver badges52 bronze badges asked Nov 13, 2013 at 10:46 ThemasterhimselfThemasterhimself 1,0164 gold badges17 silver badges25 bronze badges 3
  • 1 The coding looks OK. Can you also share, how you set the model and the model structure? – cevou Commented Nov 13, 2013 at 15:05
  • 1 the binding was indeed wrong! changed it to {path : '/details/Street'} and it works! My bad, Thanks a lot! – Themasterhimself Commented Nov 14, 2013 at 12:35
  • 1 Btw: variable names should be lower case in JS. – cschuff Commented Jan 23, 2014 at 22:20
Add a ment  | 

1 Answer 1

Reset to default 4

Here you go: http://jsbin./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./#docs/guide/CalcFields.html

发布评论

评论列表(0)

  1. 暂无评论