Page 1 of 1

Multiple conditions for a Where clauses

Posted: Fri Jun 06, 2014 4:38 am
by Erwin Will

I am trying to pass two local variables to one where clause. As seen in the documentation here http://devcenter.appery.io/documentat...

This is the code I am using. I have placed it in the Where clause.

var RestaurantNameObject = localStorage.getItem(RestaurantName);
var RestaurantHeaderObject = localStorage.getItem(RestaurantHeader);
var RestaurantNameJSON = JSON.stringify(RestaurantNameObject);
var RestaurantHeaderJSON = JSON.stringify(RestaurantHeaderObject);
return {"$and":[{"RestaurantName": RestaurantNameJSON},{"HeadingName": RestaurantHeaderJSON}]};

When I test the app I get an error with this description -- RestaurantName is not defined

I have RestaurantName and Header save in local variables from previous pages.


Multiple conditions for a Where clauses

Posted: Fri Jun 06, 2014 5:54 am
by Evgene Karachevtsev

Hello Erwin,

You should get data from localStorage this way:

codevar RestaurantNameObject = localStorage.getItem("RestaurantName"); /code
Thou you need to use ""
You get string from localStorage, not an object, so you don't have to use JSON.stringify()


Multiple conditions for a Where clauses

Posted: Fri Jun 06, 2014 10:40 pm
by Erwin Will

I updated my code to
code
var RestaurantName = localStorage.getItem("RestaurantName");
var RestaurantHeader = localStorage.getItem("RestaurantHeader");
return {"$and":[{"RestaurantName": "RestaurantName"},{"HeadingName": "RestaurantHeader"}]};
/code

but when it I run it I get this error

GET https://api.appery.io/rest/1/db/colle... 400 (Bad Request)

You can see the application here http://appery.io/app/mobile-frame?src...


Multiple conditions for a Where clauses

Posted: Sat Jun 07, 2014 7:50 pm
by Igor

Hello,

Please try use below code:
pre
var RestaurantName = localStorage.getItem("RestaurantName");
var RestaurantHeader = localStorage.getItem("RestaurantHeader");
return {"$and":[{"RestaurantName": "'+RestaurantName+'"},{"HeadingName": "'+RestaurantHeader+'"}]};
/pre