如何使用 Directus Javascript SDK 进行条件过滤?

How to do conditionally filtering with Directus Javascript SDK?

问题

我无法更改 curl 调用中的默认 AND 运算符,如 directus api 文档 中所述:

https://docs.directus.io/api/reference.html#filtering

问题

如何启用 OR 运算符以便根据不同的条件(如以下代码)进行过滤?

代码

return client
      .getItems('privileges', {
        fields: ['*', 'image.filename', 'image.data.full_url', 'attachment.*', 'partner.*.*', 'location.*', 'category.*.*', 'type.icon.data.full_url'],
        meta: ['total_count', 'result_count'],
        sort: 'created_on',

    filter: {
      'location.city': {
        'contains': lowerQ
      },
      // 'location.title': {
      //   'contains': lowerQ
      // },
      category: {
        'eq': category,
      },
      available_from: {
        'lte': 'now'
      },
      available_until: {
        'gte': 'now'
      },
    },
    limit,
    offset,
  }).then(response => {
    dispatch(getPrivilegesSuccess(key, response))
  }).catch(error => {
    console.log(error);
    dispatch(getPrivilegesFail(key, error))
  });

So, the comments out code is a different criteria that should be able to match on inserted text using the or operator. Instead it is using the AND operator in the curl output api call at the moment.

非常感谢任何类型的帮助!

filter: {
  field_one: {
    'eq': 'hello'
  },
  field_two: {
    'logical': 'or',
    'eq': 'world'
  },
},

只需将 'logical': 'or' 添加到您想要用作 'OR'

的对象