2016-09-29 31 views
0

私はsomething like this with multiple types of icons and colorsを取得しなければならないので、列内のすべてのアイコンが赤色のアイコン状態エラーまたは緑色のアイコン状態成功となるようなものである必要はありません。ここsapui5 odata値xml内容かなり

は私のコードです:

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); 

     }); 
    }, 

だから私は、それは私のロジックの良い私が欲しいものachiveするためのループだんかreasumeしますか?

答えて

0

コントローラに新しいテーブルを作成する代わりに、対応するビューでテーブルを初期化する必要があります。テーブルアイテムテンプレートでは、フォーマッタ関数を使用して値を書式設定できます。 https://sapui5.hana.ondemand.com/explored.html#/sample/sap.m.tutorial.walkthrough.23/code

あなたが最初のモデルは、テーブルとセットアップフォーマッタ機能を使用するには、所望の特性に結合行い、状態の処理のロジックを定義した:

フォーマッタ機能たとえば、リンク以下のチェックアウトフォーマッタコントローラ(例えば、1つのケースに対していくつかの値を返す)。

私はあなたが与えられたモデル名を使用してモデルをinitiallized aussumingだし、あなたは上記のコードは、あなたが見つけることができるXMLビューのための例は、Javascriptビューのために書かれ

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 
        }) 
    ] 
    }), 

sapui5バインディングについての知識を持っています上に貼り付けられたリンクに

お問い合わせ

関連する問題