Search code examples
xmlodatasapui5

How can I create a comma-separated list in SAPUI5?


I try to make a comma-separated list of authors in a headerObject.

I have a binding and expand a list of authors (ManyToMany):

<ObjectHeader responsive="true" fullScreenOptimized="true" title="{database>Title}" intro="{i18n>details_by} {database>AuthorDetails}">

This code gives me the following result:

Screenshot of UI

With {database>AuthorDetails/Name} it shows me nothing. How can I expand the authors?


Solution

  • i think we can simplify have function in the controller

    commaSeparator: function(oData) {
        if (oData === null) {
            return "";
        }
    
        var oModel = this.getView().getModel("database");
        return oData.reduce(function(result, authorKey) {
          var obj = oModel.getProperty("/" + authorKey);
          return result === "" ? obj.Name : result + ", " + obj.Name;
        }, "");
    },