【问题标题】:SAPUI5 OData Model change a property at run timeSAPUI5 OData 模型在运行时更改属性
【发布时间】:2018-07-23 16:23:39
【问题描述】:

我有一个带有网格表的 Fiori 列表报告,并且想要设置属性的状态以突出显示该行。如何在扩展控制器中检索 OData 模型并对其进行迭代以设置 property.status - "Error/Warning" 并设置回模型/刷新。

我可以将控制器中的模型设为this.getView().getModel().getProperty("/")

如何循环读取每条记录并根据某些条件设置属性的状态。

提前致谢!

【问题讨论】:

  • 你不要遍历它们。你绑定一个控件的状态属性。
  • 模型已经绑定到网格表
  • 那么你不需要循环来更新状态。可以在格式化程序中提供条件。
  • 谢谢,你有任何参考/链接/代码sn-ps
  • 在答案中提供

标签: model odata sapui5


【解决方案1】:

格式化标签控制器的示例(使用 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>

【讨论】:

  • 感谢代码 sn-p。但是,对于列表报告模板来说,这很棘手。找到了另一种添加附加列并将其设置为有效的格式化程序的方法。谢谢...
猜你喜欢
  • 2019-07-18
  • 1970-01-01
  • 1970-01-01
  • 2020-03-16
  • 1970-01-01
  • 2017-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多