我必须实现与多种类型的图标和颜色类似,所以列中的所有图标都不应该像红色图标状态错误或者绿色图标状态在oData值的基础上成功一样。
这是我的代码:
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);
});
},因此,为了实现我想要的东西,我如何循环,这是我的逻辑好吗?
发布于 2016-09-30 06:44:07
与其在控制器中创建新表,不如在相应的视图中插入表。在表项模板中,可以使用格式化程序函数格式化值。
对于格式化程序函数示例,请查看以下链接:https://sapui5.hana.ondemand.com/explored.html#/sample/sap.m.tutorial.walkthrough.23/code
首先在表中执行Model绑定并设置使用格式化程序函数所需的属性,然后在格式化控制器中定义状态处理的逻辑(例如,返回某个情况下的值)。
我想请您用给定的模型名来初始化您的模型,并且您已经了解了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视图的示例。
诚挚的问候
https://stackoverflow.com/questions/39780777
复制相似问题