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

标签 javascript directus headless-cms

问题

我无法更改 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'
  },
},

只需将 'logic': 'or' 添加到您想要用作“OR”的对象

关于javascript - 如何使用 Directus Javascript SDK 进行条件过滤?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57867151/

相关文章:

javascript - 使用许多 <li> 延迟加载长 <ul> 的最简单方法

mysql - Directus ER_ACCESS_DENIED_ERROR : Access denied for user 'root' @'localhost' (using password: YES)

postgresql - strapi database.js/多个数据库配置

content-management-system - Sanity CMS 前端未应用文本突出显示

javascript - Node.js 5.5.0 console.log 不会记录

javascript - 如何检测数组是否包含特定长度的值

vue.js - Promise 被拒绝并且无法在 VUE 和 Directus 中获取 Collections 或 getItems

directus - 是否可以通过 API 或应用程序硬删除 Directus 项目?

mysql - 在配置为使用 MySql 的 Strapi 中,如何在代码中创建新的内容类型记录?

javascript - 如何阻止图像在达到某个点后缩小?