2017-02-22 65 views
0

我正在尝试使用Loopback的AngularJS SDK,但是我没有找到一种方法来用多个where子句(并且在文档中没有示例)执行请求。Loopback multiple 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) { 
    [...] 
}); 

确切相同的错误代码是显示ayed。 有什么想法?

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

$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] 

回答

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")} } 
    ] 
} 
+0

谢谢您的回答。它并没有真正的工作(我编辑了我的第一篇文章)。或者,也许你的解决方案解决了第一个问题,但已经创建了一个新问题。 – ThomasF62

+0

那个错误不是关于where子句,你现在有日期的问题,快乐调查 – Yaser

+0

感谢您的时间 – ThomasF62