【问题标题】:Loopback multiple where clause client side环回多个where子句客户端
【发布时间】:2017-07-13 02:52:33
【问题描述】:

我正在尝试使用 Loopback 的 AngularJS SDK,但我没有找到使用多个 where 子句执行请求的方法(并且文档中没有示例)。

$scope.events = Professional.events({
        id: '1',
        filter: {
          where: {
            EndDate: {gt: new Date("2017-05-20T00:00:00.000Z")}
          }
        }
      },
    function(err) {
      [...]
    });

这个例子完美运行,但我想这样做:

$scope.events = Professional.events({
        id: '1',
        filter: {
          where: {
            and: {
              EndDate: {gt: new Date("2017-05-20T00:00:00.000Z")},
              EndDate: {it: new Date("2017-06-20T00:00:00.000Z")}
            }
          }
        }
      },
    function(err) {
      [...]
    });

终端显示的错误

Error: The and operator has invalid clauses {"EndDate":{"it":"2017-06-20T00:00:00.000Z"}}: Value is not an array or object with sequential numeric indices

再试一次:

$scope.events = Professional.events({
    id: '1',
    filter: {
      where: {
        EndDate: {gt: new Date("2017-05-20T00:00:00.000Z")},
        EndDate: {it: new Date("2017-06-20T00:00:00.000Z")}
      }
    }
  },
function(err) {
  [...]
});

显示完全相同的错误代码。 有什么想法吗?

编辑:此解决方案不起作用

$scope.events = Professional.events({
        id: '1',
        filter: {
          where: {
            and: [
              {EndDate: {gt: new Date("2017-05-20T00:00:00.000Z")} },
              {EndDate: {it: new Date("2017-06-20T00:00:00.000Z")} }
            ]

          }
        }
      }
      ,
    function(err) {
      [...]
    });

代码错误(500 http)

Erreur non traitée pour la demande GET /api/Professionals/1/events?filter=%7B%22where%22:%7B%22and%22:%5B%7B%22EndDate%22:%7B%22gt%22:%222017-05-20T00:00:00.000Z%22%7D%7D,%7B%22EndDate%22:%7B%22it%22:%222017-06-20T00:00:00.000Z%22%7D%7D%5D%7D%7D : Error: Date non valide : [object Object]

【问题讨论】:

    标签: javascript angularjs strongloop loopback


    【解决方案1】:

    如果您尝试将多个条件与and 进行比较,则必须将数组传递给并像这样:

    where: 
    {
        and: [
            {title: 'My title'}, 
            {content: 'Hello'}
        ]
    }
    

    上面的代码意味着给我所有标题是“我的标题”和内容是“你好”的数据。

    在你的情况下是:

    where: {
        and: [
            { EndDate: {gt: new Date("2017-05-20T00:00:00.000Z")} },
            { EndDate: {it: new Date("2017-06-20T00:00:00.000Z")} }
        ]
    }
    

    【讨论】:

    • 感谢您的回答。它并没有真正起作用(我编辑了我的第一篇文章)。或者,也许您的解决方案解决了第一个问题,但已经创建了一个新问题。
    • 该错误与 where 子句无关,您现在的日期有问题,调查愉快
    • 感谢您的宝贵时间
    猜你喜欢
    • 2019-06-10
    • 2016-08-31
    • 2013-10-29
    • 2011-08-31
    • 2020-09-28
    • 2010-10-10
    • 2018-09-05
    • 2017-07-26
    • 1970-01-01
    相关资源
    最近更新 更多