我有一个带有网格表的Fiori列表报表,并且想要设置属性的状态以突出显示该行。如何在扩展控制器中检索OData模型,并对其进行迭代以设置 property.status-“错误/警告” ,并重新设置模型/刷新。
我能够以this.getView().getModel().getProperty("/")
的身份在控制器中获取模型
如何遍历它以读取每个记录并根据某种条件设置属性的状态。
谢谢!
答案 0 :(得分:0)
用于格式化标签控制器的示例(使用setInterval模拟模型更改)-http://jsbin.com/pacexa/edit?html,js,output
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta charset="UTF-8">
<title>Text</title>
<script id="sap-ui-bootstrap" type="text/javascript" src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js" data-sap-ui-theme="sap_bluecrystal" data-sap-ui-libs="sap.m" data-sap-ui-xx-bindingSyntax="complex">
</script>
<!-- XML-based view definition -->
<script id="oView" type="sapui5/xmlview">
<mvc:View height="100%" controllerName="myView.Template" xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" class="viewPadding">
<Label text="{path:'/status', formatter: 'myFormatter.formatText'
}" />
</mvc:View>
</script>
<script>
//Formatter Definition
var myFormatter = {
formatText: function(status) {
if (status === "OK") {
return "Good";
}
return "Bad";
}
};
// Controller definition
sap.ui.define([
'jquery.sap.global',
'sap/ui/core/mvc/Controller',
'sap/ui/model/json/JSONModel'
], function(jQuery, Controller, JSONModel) {
"use strict";
var cController = Controller.extend("myView.Template", {
onInit: function(oEvent) {
var oModel = new JSONModel({
status: "OK",
});
var oView = this.getView();
oView.setModel(oModel);
setInterval(function() {
oModel.setProperty("/status", oModel.getProperty("/status") === "OK" ? "ERR" : "OK");
}, 1000);
}
});
return cController;
});
// Instantiate the View and display
var oView = sap.ui.xmlview({
viewContent: jQuery('#oView').html()
});
oView.placeAt('content');
</script>
</head>
<body class="sapUiBody" role="application">
<div id="content"></div>
</body>
</html>