簡體   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