2016-09-29 35 views
0

我必須創建something like this with multiple types of icons and colors因此,並非列中的所有圖標都應該像它可能是基於oData值的red-icon-status-error或green-icon-status-success。sapui5 odata value xml content pretty

這裏是我的代碼:

var jsonModel = new sap.ui.model.json.JSONModel(); 
       var Source; 
       var clr; 
       jsonModel.setData(oData);.. 

for (var i = 0; i < oData.results.length; i++) { 

      iconSource = oData.results[i].ST; 
      switch (iconSource) { 
      case 'E': 
      { 
       Source = "sap-icon://status-error"; 
       clr = "red"; 
      } 
      break; 
      case 'S': 
      { 
       Source = "sap-icon://status-completed"; 
       clr = "green"; 
      } 
      break; 
      default: 
      { 
       Source = "sap-icon://status-critical"; 
       clr = "grey"; 
      } 
      break; 
      } 
var jsonModel = new sap.ui.model.json.JSONModel(); //set new json model 
      jsonModel.setData(oData);//set the json 
      var view = that.getView();//get view 
      }//i close the for loop 
      var exempletable = sap.ui.getCore().byId(view.createId('tableviewid')); 
      var statusLabel = new sap.m.Label(); 
      statusLabel.setText("Stat"); 
       var statusColumn = new sap.ui.table.Column({ 
       label: statusLabel, 
       template: new sap.ui.core.Icon({ 
        src : Source, 
        color : clr 
       }), 
       width: "40px" 
      }); 
     exempletable.insertColumn(statusColumn, 0);//here insteed of 0 it should be something like 0+i? 
     exempletable.setModel(jsonModel);//set model 
    exempletable.bindRows("/results");//bind rows 
     exempletable.setVisibleRowCount(10); 
     exempletable.setEnableSelectAll(false); 
      exempletable.setSelectionMode(sap.ui.table.SelectionMode.SingleSelectMaster); 
      exempletable.setNavigationMode(sap.ui.table.NavigationMode.Scrollbar); 

     }); 
    }, 

所以要reasume我怎麼循環,從而才達到我想要的東西,這是我的邏輯好?

回答

0

而不是在控制器中創建一個新表,你應該在相應的視圖中初始化表。在表格項目模板中,您可以使用格式化函數格式化值。

對於格式化功能例如,檢查下面的鏈接: https://sapui5.hana.ondemand.com/explored.html#/sample/sap.m.tutorial.walkthrough.23/code

你先做模型在表和設置所需的屬性,以使用格式化功能結合,的狀態處理邏輯在被定義格式化程序控制器(例如,爲一個案例返回一些值)。

我aussuming你initiallized模型與給定的型號名稱和您有關於sapui5綁定

var oExampleItemTemplate = new sap.m.ColumnListItem("idexampletemplate", { 
       unread: false, 
       cells: [ 
        new sap.m.StandardListItem({ 
// The code after the comma within the title brackets calls the formatter function      
title: "{parts: [ {path: 'your_model_name>property_name'} ], formatter: '<resourceroot.path.to.formatter.class.convertValueIntoMaterialGroup'}", 
         description: "{your_model_name>property_name}", 
         adaptTitleSize: false, 
         iconInset: true 
        }) 
    ] 
    }), 

上面的代碼被用於一個JavaScript寫的看法,你可以找到一個XML視圖的例子知識在上面粘貼的鏈接中。

致以問候