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.
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
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
How can I give the request and currentdate parameters to the filter function, or how do I write this? 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.
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.
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) { ...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.