2016-08-01 129 views
0

我有一個角度爲Kendo UI Grid,它從我的數據源讀取一系列屬性。 其中之一包含一個顏色字符串。我想使用上述顏色字符串來爲網格中的方框設置背景顏色。Kendo UI Grid和ng風格

我使用的盒子下面的模板:

template: "<img class='alarm-box-prediction variable' ng-style={'background-color': dataItem.type}'></img>" 

從我的數據源的相關數據如下:

dataSource: { 
     dataSource: function(data) { 
      // Map the stored properties in the data array of objects received to 
      // their corresponding columns in the Grid 
      return $.map(data, function(alarmProperty) { 
       return { 
        // Change array index to match API once we are getting data from there 
        type: alarmProperty[0], 
        //... there are more properties here but i removed them as they are not the focus 
       }; 
      }); 
     }, 

從JSON文件,該文件是當前服務相關的數據因爲我的DS(即將更改)是:

{ 
    "alarms": [ 
     { 
      "type": "Yellow", 
//... 
     } 
//... 
]} 

回答

0

找到了問題。 ng樣式需要以不同的格式進行格式化,因爲它作爲字符串傳遞給kendo。

template: "<img class='alarm-box-prediction variable' ng-style=\"{'background-color':dataItem.type}\"></img>",