【问题标题】:Filter function on where clause on Azure mobile services Node.jsAzure 移动服务 Node.js 上 where 子句的筛选功能
【发布时间】:2017-03-07 21:35:27
【问题描述】:

我正在尝试在之前链接中描述的 where 子句中的 table object 上使用过滤器功能,但我找不到有关如何编写它的任何参考。

     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 参数提供给过滤函数,或者我该如何编写? This 也没有帮助。

【问题讨论】:

    标签: javascript node.js azure azure-mobile-services


    【解决方案1】:

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

    生成格式如下:

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

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

    所以根据你的代码,你可以尝试修改为如下代码sn-p:

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

    【讨论】:

    • 我可以传递一些函数作为参数吗?
    猜你喜欢
    • 2016-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多