Kendo UI网格和ng风格

时间:2016-08-01 14:33:25

标签: javascript angularjs kendo-ui kendo-grid ng-style

我有一个角度的Kendo UI网格,它从我的数据源读取一系列属性。 其中一个包含颜色字符串。我想使用所说的颜色字符串来设置网格中方框的背景颜色。

我在框中使用以下模板:

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

我的dataSource的相关数据如下:

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

当前作为我的DS的JSON文件相关的数据(尽快会更改)是:

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

1 个答案:

答案 0 :(得分:1)

发现了这个问题。 ng-style需要以不同的格式进行格式化,因为它将作为字符串传递给kendo。

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