XML 中的多个过滤器 [英] Multiple Filters in XML

查看:26
本文介绍了XML 中的多个过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个列表,但如果它的 '05''01' 不显示在列表中,我想过滤掉类型.以下代码适用于 '05' 但不适用于 '01'.我将如何编写它以添加另一个值?

So I have a list but I want to filter out the type if its '05' or '01' to not display in the list. The following code work fine for '05' but not '01'. How would I write it to add another value?

items="{
  path: 'Entries',
  filters: [{
    path: 'Type',
    operator : 'NE',
    value1 : '05',
    value2: '01'
  }]
}"

我尝试了这个,我认为这是合乎逻辑的方式,但它随后开始显示 05 和 01.所以我认为这是使用 OR 过滤器而不是过滤器 AND 过滤器组合.

I tried this which I would assume is the logical way, but it then started displaying both 05 and 01. So I assume this is using an OR filter rather than filter AND filter combined.

items="{
  path:'Entries',
  filters: [{
    path: 'Type',
    operator: 'NE',
    value1: '05'
  }, {
    path: 'Type',
    operator: 'NE',
    value1: '01'
  }]
} 

推荐答案

以下是 XML 视图中的语法:

Here is the syntax in XML view:

items="{
  path: '/Products',
  filters: [
    {
      filters: [
        {
          path: 'ProductName',
          operator: 'StartsWith',
          value1: 'Sir '
        },
        {
          path: 'Discontinued',
          operator: 'EQ',
          value1: false
        },
      ],
      and: true
    }
  ]
}"

工作示例:https://embed.plnkr.co/wAlrHB?show=view/Home.view.xml,预览

参数 filters 等待过滤器信息对象的数组.过滤器信息对象受限于以下属性组合:

The parameter filters awaits an array of filter info objects. A filter info object is constrained in the following combinations of properties:

  • pathoperatorvalue1(和 value2,如果适用)
  • 或者 filtersand.<-- 这就是我们需要的.
  • path, operator, value1 (and value2 if applicable)
  • Or filters and and. <-- This is what we need.

API 参考:sap.ui.model.Filter

API reference: sap.ui.model.Filter

您的第二种方法不起作用的原因是,两个过滤器都指向导致 OR 逻辑的同一路径 ('Type').

The reason, why your second approach didn't work, is because both filters were pointing to the same path ('Type') which results in OR logic.

应用于单个表列的所有过滤器都是 OR 运算,而不同表列的过滤器是 AND 运算.请使用过滤器的自动分组(如果适用)或使用显式 AND/OR 过滤器,不支持两者的混合.[来源]

All filters applied to a single table column are ORed, while filters on different table columns are ANDed. Please either use the automatic grouping of filters (where applicable) or use explicit AND/OR filters, a mixture of both is not supported. [source]

这篇关于XML 中的多个过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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