簡體   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