简体   繁体   English

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

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

I'm trying to use a filter function on a table object in the where clause described in the link before, but I can't find any reference about how to write it. 我试图在前面的链接中所述的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) { ...

but in this way, I get Error: Expected value(s) for parameter(s) request,currentdate 但以这种方式,我得到Error: Expected value(s) for parameter(s) request,currentdate

and if I write it this way: 如果我这样写:

   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) { ...

I get ReferenceError: request is not defined 我收到ReferenceError: request is not defined

How can I give the request and currentdate parameters to the filter function, or how do I write this? 如何将request和currentdate参数提供给过滤器函数,或者如何编写呢? This didn't help either. 也没有帮助。

When using where(function) of table object , we should add the value of the parameter following the function(){} construct in the where closure. 当使用表对象的 where(function)时,我们应该在where闭包中的function(){}构造之后添加参数的值。

Generate as the format like: 生成为以下格式:

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

And it seems that it will raise the TypeError: Converting circular structure to JSON issue if directly set request object in the where function. 而且,如果直接在where函数中设置request对象,则似乎会引发TypeError: Converting circular structure to JSON问题。

So according your code, you can try to modify it as the following code snippet: 因此,根据您的代码,您可以尝试将其修改为以下代码段:

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