繁体   English   中英

使用 and:false 条件 SAPUI5 过滤日期范围的 Odata 服务值

[英]Filtered the Odata service value for date range with and:false condition SAPUI5

在此处输入图像描述我想实现 sap.ui.model.Filter 有新的 sap.ui.model.Filter(sPath, sap.ui.Z20F35E630DAF44DB1,4C3F68F53.9) 像这样我有 8 个字段,我只像这样过滤,但是对于 2 个字段,我需要实现and:False条件。

https://sapui5.hana.ondemand.com/#/api/sap.ui.model.Filter

 var product = comboBoxValue.products; product.forEach(function (allproduct) { allproduct = allproduct.toUpperCase(); var productValue1 = new sap.ui.model.Filter("PRODUCT", sap.ui.model.FilterOperator.Contains, allproduct); filters.push(productValue1); }); // filter the Country values var country = comboBoxValue.locations; country.forEach(function (allcountry) { // allcountry = allcountry.toUpperCase(); var countryValue = new sap.ui.model.Filter("COUNTRY", sap.ui.model.FilterOperator.Contains, allcountry); // filters.push(countryValue); }); // filter the Status value var status = comboBoxValue.status1; status.forEach(function (allstatus) { // allcountry = allcountry.toUpperCase(); var statusValue = new sap.ui.model.Filter("SUB_STATUS1", sap.ui.model.FilterOperator.Contains, allstatus); filters.push(statusValue); }); // filter the Change type values var change_type = comboBoxValue.changes; change_type.forEach(function (allchanges) { // allcountry = allcountry.toUpperCase(); var changeValue = new sap.ui.model.Filter("CHANGE_TYPE", sap.ui.model.FilterOperator.Contains, allchanges); filters.push(changeValue); }); // filter the Submission type values var sub_type = comboBoxValue.Submissions1; sub_type.forEach(function (allsub) { allsub = allsub.toUpperCase(); subValue = new sap.ui.model.Filter("SUB_TYPE", sap.ui.model.FilterOperator.Contains, allsub); filters.push(subValue); }); // filter the Manufacturing Stage var manu_stage = comboBoxValue.stages1; manu_stage.forEach(function (allstage) { allstage = allstage.toUpperCase(); var stageValue = new sap.ui.model.Filter("MANUFACTURING_STAGE", sap.ui.model.FilterOperator.Contains, allstage); filters.push(stageValue); });

过滤器是我传递给oData服务的数组,例如

 oModel6.read("/gantt", { filters: filters, success: function (oData, oResponse) { // checking if its region Gantt Chart view console.log("filtered data will come in oData "); } error: function(e){ } });

现在我给了六个过滤器。push(productValue1); 传递 var productValue1 = new sap.ui.model.Filter("PRODUCT", sap.ui.model.FilterOperator.Contains, allproduct); 使用 Sapui5 控制过滤器对其进行过滤。 阵列过滤器。 现在我想要2个日期范围的过滤器

 for (var g = 0; g < comboBoxValue.date_type.length; g++) { var range = new sap.ui.model.Filter(comboBoxValue.date_type[g], sap.ui.model.FilterOperator.BT, sFrom, sTo); oFilter.push(range); }

在这我传递了多个 comboBoxValue.date_type 值和开始日期,结束日期
对于其他过滤器,其标准 sapui5 采用和:true (您参考https://sapui5.hana.ondemand.com/#/api/sap.ui.model.Filter此链接)

但是对于这个特定的过滤器,我需要给出 and:false 并将这个 and:false 给我的过滤器数组过滤器

最终声明:总共 8 个值,其中 6 个是普通标准过滤器,使用and:true并存储在过滤器数组中,另外 2 个字段日期范围使用 dat_type 需要和:false并将其存储在过滤器数组中

在图像 2 中的值是我想要的and:false和其他 in and:true

据我了解您的问题,您总共有 8 个条件,您希望其中 6 个与“或”连接,其中两个与“和”连接。 此行为在带有示例 #3 的文档中进行了解释。

new Filter({
filters: [
  ...
  new Filter({
    path: 'Quantity',
    operator: FilterOperator.LT,
    value1: 20
  }),
  new Filter({
    path: 'Price',
    operator: FilterOperator.GT,
    value1: 14.0
  })
  ...
],
and: true|false

})

这表明您可以在过滤器中嵌套过滤器,这将是您解决问题的方式。 在您的情况下,您将需要三层嵌套。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM