Sapui5 如何基于sap.m.table行中某个单元格中的数据将CSS应用于该行

Sapui5 如何基于sap.m.table行中某个单元格中的数据将CSS应用于该行,sapui5,Sapui5,我正在使用sap.m.table。我需要根据表中某一列中的数据应用或更改某些行的背景色 我正在使用以下代码,但它不起作用 创建了CSSfile:test.css <style type="text/css"> .Total { background-color: LightSteelBlue !important; } </style> 在Controller中。我定义了以下方法,将样式表单独应用于表中的特定行。 "resources"

我正在使用sap.m.table。我需要根据表中某一列中的数据应用或更改某些行的背景色

我正在使用以下代码,但它不起作用

创建了CSSfile:test.css

<style type="text/css">
    .Total {
        background-color: LightSteelBlue  !important;
    }
</style>
在Controller中。我定义了以下方法,将样式表单独应用于表中的特定行。

"resources": {
    "css": [
        {
            "uri": "css/test.css"
        }
    ]
}
rowColours: function() {
    var oController = this;
    console.log("rowColours() --> Start ");
    var oTable = this.oView.byId("tblAllocation");
    var rows = oTable.getItems().length; //number of rows on tab

    //start index 
    var row;
    var cells = [];
    var oCell = null;
    for (i = 0; i < oTable.getItems().length; i++) {
        //console.log("rowColours() :: row--> "+row);
        //actualRow = oTable.getItems(); //content
        if (i == 0) {
            row = oTable.getItems()[i];
            cells = cells.concat(oTable.getItems()[i].getCells());
            //getting the cell id
            oCell = cells[2];

            oCell = oCell.toString().substring(29, oCell.length);
            otemp = this.getView().byId(oCell).getText();

            if (otemp.toString() == "TotalAllocation") {
                oTable.getItems()[i].$().taggleClass("grandTotal");
            }
        }
    }
    console.log("rowColours() --> end ");
}
错误: 未捕获的TypeError:无法读取未定义的属性“getText”

以下代码是否可以更改行bg颜色

if (otemp.toString() == "TotalAllocation") {
    oTable.getItems()[i].$().taggleClass("Total");
}
请让我知道如何更改bg颜色或应用sap.m.表中相应行的样式


谢谢

您下面的方法不正确。最好使用格式化程序

示例:

var oTable = new sap.m.Table({
    columns: [
        new sap.m.Column({
            header: new sap.m.Label({
                text: "Name"
            }),
        }),
    ],
    items: {
        path: 'modelList>/',
        template: new sap.m.ColumnListItem({
            cells: [
                new sap.m.Text({
                    //formatter to the text property on sap.m.Text control.    
                    text: {
                        parts: [{
                            "path": "modelList>Name"
                        }],
                        formatter: function(name) {
                            if (name == "TotalAllocation") {
                                // use this.getParent().. until u get the row.    like this below and add class.
                                this.getParent().getParent().addStyleClass("Total");
                            }
                        }
                    }
                })
            ]
        })
    }
});
var oTable = new sap.m.Table({
    columns: [
        new sap.m.Column({
            header: new sap.m.Label({
                text: "Name"
            }),
        }),
    ],
    items: {
        path: 'modelList>/',
        template: new sap.m.ColumnListItem({
            cells: [
                new sap.m.Text({
                    //formatter to the text property on sap.m.Text control.    
                    text: {
                        parts: [{
                            "path": "modelList>Name"
                        }],
                        formatter: function(name) {
                            if (name == "TotalAllocation") {
                                // use this.getParent().. until u get the row.    like this below and add class.
                                this.getParent().getParent().addStyleClass("Total");
                            }
                        }
                    }
                })
            ]
        })
    }
});