繁体   English   中英

Azure移动服务Node.js上where子句的筛选器功能

[英]Filter function on where clause on Azure mobile services Node.js

我试图在前面的链接中所述的where子句中对表对象使用过滤器功能,但是找不到有关如何编写它的参考。

     exports.post = function(request, response) {
       var currentdate = (new Date()).getTime();
       takenOffersTable.where(function(request,currentdate){
       return (this.user_id ==  request.user.userId && this.offer_id == request.body.offer_id && this.__updatedAt < currentdate)
       }).read({ success: function(result) { ...

但以这种方式,我得到Error: Expected value(s) for parameter(s) request,currentdate

如果我这样写:

   exports.post = function() {
       var currentdate = (new Date()).getTime();
       takenOffersTable.where(function(request,currentdate){
       return (this.user_id ==  request.user.userId && this.offer_id == request.body.offer_id && this.__updatedAt < currentdate)
       }).read({ success: function(result) { ...

我收到ReferenceError: request is not defined

如何将request和currentdate参数提供给过滤器函数,或者如何编写呢? 也没有帮助。

当使用表对象的 where(function)时,我们应该在where闭包中的function(){}构造之后添加参数的值。

生成为以下格式:

var variable1,variable2;
...
tableObject.where(function(parameter1,parameter2,...){},variable1,variable2,...)
...

而且,如果直接在where函数中设置request对象,则似乎会引发TypeError: Converting circular structure to JSON问题。

因此,根据您的代码,您可以尝试将其修改为以下代码段:

exports.post = function(request, response) {
       var currentdate = (new Date()).getTime();
       takenOffersTable.where(function(user,body,currentdate){
       return (this.user_id ==  user.userId && this.offer_id == body.offer_id && this.__updatedAt < currentdate)
       },request.user,request.body,currentdate).read({ success: function(result) { ...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM