绑定选定日期日历的日期聚合 [英] Bind selectedDates Aggregation for Calendar

查看:23
本文介绍了绑定选定日期日历的日期聚合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将日期数组绑定到sap.ui.unified.Calendar,但没有成功。我确信我离解决方案不远了。

代码如下:

var oCal = new sap.ui.unified.Calendar();
var oModel2 = new sap.ui.model.json.JSONModel([
    {myDate: new Date("2018-01-10"), tt:""},
    {myDate: new Date("2018-01-11"), tt:""},
    {myDate: new Date("2018-01-12"), tt:""},
]);
sap.ui.getCore().setModel(oModel, "MyData3");
var oItemTemplate = new sap.ui.unified.DateRange({
    startDate: "{MyData3>myDate}",
    endDate: "{MyData3>myDate}"
});     
oCal.bindAggregation("selectedDates", "MyData3>/", oItemTemplate);

我没有得到任何例外。模型具有用Date类型的3个对象填充的数据,但我没有在日历中预先选择这3个日期。

如果我手动(未绑定)填写selectedDates聚合,它将选择这3个日期。

推荐答案

以下是一个有效的最小示例:

sap.ui.getCore().attachInit(() => sap.ui.require([
  "sap/ui/unified/Calendar",
  "sap/ui/unified/DateRange",
  "sap/ui/model/json/JSONModel",
], (Calendar, DateRange, JSONModel) => new Calendar({
  singleSelection: false
}).bindAggregation("selectedDates", {
  path: "MyData3>/",
  template: new DateRange({
    startDate: "{MyData3>myDate}",
    endDate: "{MyData3>myDate}",
  }),
}).setModel(new JSONModel([
  {myDate: new Date("2018-01-10")},
  {myDate: new Date("2018-01-11")},
  {myDate: new Date("2018-01-13")},
]), "MyData3").placeAt("content")));
<script src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js" id="sap-ui-bootstrap"
  data-sap-ui-libs="sap.ui.unified"
  data-sap-ui-preload="async"
  data-sap-ui-theme="sap_belize"
  data-sap-ui-compatVersion="edge"
></script><body id="content" class="sapUiBody sapUiSizeCompact"></body>

我假设您问题中提供的代码不是您的项目的真实摘录。否则,您将得到一个ReferenceError,指出变量oModel未定义(相反,oModel2已定义)。除此之外,绑定不起作用的实际原因一定是因为模型设置在核心上,而Calendar控件是ComponentContainer的后代。在这种情况下,核心模型将不会传播到组件。

-->Avoid setting models on the Core if the app is component-based.


如果尚未启用:为了首先显示多个选定日期,必须显式禁用Calendar属性singleSelection,因为默认情况下该属性处于启用状态。

这篇关于绑定选定日期日历的日期聚合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆