Page 1 of 2

GET results using 2 Local Storage values into a single constraint ParseDB

Posted: Wed Oct 31, 2012 3:06 am
by egonzalez

Hi,
I'm using ParseDb and I'm trying to pass in 1 constraint consisting of 2 local storage values. I've used 1 local storage value in the past without any issues. I would typically substitute the objectID value for "'+value+'" which always works well. I realize that mapping 2 local storage values to the query will not work this way. How should I identify each local storage value?
This is the query I am working with:

{"teacher":{"type":"Pointer","className":"_User","objectId":"MSSmmyU1BX"},"granted":false,"event": { "type": "Pointer", "className": "Event", "objectId": "nfQCCBMGkl" }}

Thanks
Eric


GET results using 2 Local Storage values into a single constraint ParseDB

Posted: Wed Oct 31, 2012 3:37 am
by maxkatz

In JavaScript mapping for the paramater, use the local storage API directly:

code
var value1 = localStorage.getItem("value1");

var value2 = localStorage.getItem("value2");
/code

then create the string you need to return.


GET results using 2 Local Storage values into a single constraint ParseDB

Posted: Wed Oct 31, 2012 11:55 am
by egonzalez

I'm adding this to the javascript for the request mapping but it's not working. What am I missing?

var event = localStorage.getItem("eventIdLS");
var user = localStorage.getItem("userIdLS");
return '{"teacher":{"type":"Pointer","className":"_User","objectId":user},"granted":false,"event": { "type": "Pointer", "className": "Event", "objectId":event}}';


GET results using 2 Local Storage values into a single constraint ParseDB

Posted: Wed Oct 31, 2012 12:29 pm
by Maryna Brodina

Hello! Could you clarify what exactly doesn't work? Maybe this can help https://www.parse.com/docs/rest#queries


GET results using 2 Local Storage values into a single constraint ParseDB

Posted: Wed Oct 31, 2012 4:23 pm
by maxkatz

Before you add the values from local storage, make sure the return works as a plain string.


GET results using 2 Local Storage values into a single constraint ParseDB

Posted: Wed Oct 31, 2012 4:29 pm
by egonzalez

When I test the return in the Services (Test Connection) section , it works perfectly. Is that what you are talking about?


GET results using 2 Local Storage values into a single constraint ParseDB

Posted: Wed Oct 31, 2012 4:32 pm
by maxkatz

That's good. Next you should test it from the page, in mapping. But don't insert the values from local storage yet, hard code them into the return string.


GET results using 2 Local Storage values into a single constraint ParseDB

Posted: Wed Oct 31, 2012 4:49 pm
by egonzalez

It works hardcoded on the page. =) I must be doing something wrong with the syntax.


GET results using 2 Local Storage values into a single constraint ParseDB

Posted: Wed Oct 31, 2012 4:51 pm
by maxkatz

Use console.log(..) on the string you create..use it in Test Connection.


GET results using 2 Local Storage values into a single constraint ParseDB

Posted: Wed Oct 31, 2012 5:06 pm
by egonzalez

This is what I am using.
var event = localStorage.getItem("eventIdLS");
var user = localStorage.getItem("userIdLS");
return '{"teacher":{"type":"Pointer","className":"_User","objectId":user},"granted":false,"event": { "type": "Pointer", "className": "Event", "objectId":event}}';
console.log(value);

and this is what I get in the console:

OPTIONS https://api.parse.com/1/classes/EPS?w... 200 (OK)

GET https://api.parse.com/1/classes/EPS?w... 400 (Bad Request)