2017-07-24 41 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; 
    } 
} 
});