【问题标题】:Growing table not working with JSONModel增长表不适用于 JSONModel
【发布时间】:2016-10-11 02:09:37
【问题描述】:

我需要使用 sap.m.Table 来显示大约 200 个条目。我知道我需要使用不断增长的财产。但是,当我添加“growth: true,growthThreshold: 100”时,表格仍然显示 100 个条目,并且没有显示“更多”按钮。

我已经阅读了一些与此问题相关的博客文章。我尝试了我的模型的 setSizeLimit,但它没有用。我正在使用具有默认 countMode 的 JSONModel。还有什么我可以尝试的吗?

谢谢!

【问题讨论】:

    标签: sapui5


    【解决方案1】:

    设置大小限制与不断增长的功能无关,它只会影响列表绑定中使用的最大条目数,例如您已经存储了 1000 个条目,并且大小限制为 500,任何绑定到这些条目的列表控件将只显示 500。

    JSONModel 或多或少是一个愚蠢的数据存储,它不支持不断增长的功能,因为它不了解您的数据以及如何获取总体计数。要实现这一点,您需要实现自己的列表绑定,该绑定计算您的特定案例的数据计数。您还需要一个使用此列表绑定的自定义模型。

    JSON模型

      sap.ui.define([
           "sap/ui/model/json/JSONModel",
           "xxx/ListBinding"
      ], function(JSONModel, ListBinding) {
          "use strict";
    
          return JSONModel.extend("xxx.JSONModel", {
    
              bindList : function(path, context, sorters, filters, parameters) {
                  return new ListBinding(this, path, context, sorters, filters, parameters);
              };
          });
    
      });
    

    列表绑定

      sap.ui.define([
          "sap/ui/model/json/JSONListBinding"
      ], function(ListBinding) {
          "use strict";     
    
          return ListBinding.extend("xxx.ListBinding", {
    
              // in this case the array holding the data has a count property which stores the total number of entries
              getLength : function() {
                  var path = !this.sPath ? "count" : this.sPath + "/count";
                  var count = this.oModel.getProperty(path, this.oContext);
                  return (count) ? count : ListBinding.prototype.getLength.call(this);
              }
    
          });
    
    }); 
    

    【讨论】:

    • 感谢您的意见!但是,我通过执行以下操作以某种方式解决了我的问题:
    • 我改变了我的 oTable.bindAggregation("","dfcr>/",oTemplate); to oTable.bindAggregation("items","dfcr>/",oTemplate);
    • 请提供一个运行示例。
    • BaseBinding 定义在哪里?
    • 应该是 JSONListBinding。似乎类名会随着时间而变化,因此您需要检查 openui5/src/sap.ui.core/src/sap/ui/model/json/JSONModel.js 中的github.com/SAP/openui5
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-21
    • 1970-01-01
    • 1970-01-01
    • 2020-12-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多