2017-07-24 89 views
0

如果我有這樣的使用JSON數據綁定

[{"processor":"Mr. XYZ","components":["asd","efg","ghi","fjk"]} , 
{"processor":"Mr. XYZ","components":["asd","efg","ghi","ghi"]} , 
{"processor":"Mr. XYZ","components":["asd","efg","lkl"]} ] 

JSON數據SAP UI5如果我結合這一個表:

<Table id="myt1" items="{path: '/'}"> 
    <columns> 
     <Column> 
      <Label text="Processor"/> 
     </Column> 
     <Column> 
      <Label text="Components"/> 
     </Column> 
    </columns> 
    <items> 
     <ColumnListItem> 
      <Text text="{processor}"/> 
      <Text text="{components}"/> 
     </ColumnListItem> 
    </items> 
</Table> 

如何組件在不同的線路數組綁定在該表中的處理器的單元格中? 請參考圖片尋找我正在尋找的輸出。

在此先感謝!

Desired output

回答

0

你可以使用文本格式化每個數組元素後添加一個新行。

<ColumnListItem> 
       <Text text="{processor}"/> 
       <Text text="{ 
        path: 'components', 
        formatter: '.formatter.formatText' 
       }"/> 
</ColumnListItem> 

格式化:

sap.ui.define([], function() { 
"use strict"; 
return { 

    formatText : function(s){ 
     var sOut = ""; 
     s.forEach(function(sTxt){ 
      sOut += sTxt + "\n"; 
     }); 
     return sOut; 
    } 
} 
});