Page 1 of 1

Simple Javascript question

Posted: Fri Jul 11, 2014 2:53 am
by Peter Viglietta

Hi.. I need to add some javascript to the 'where' request parameter on a query service that will show my users a list of Posts on a message board in my app. The Posts collection has columns for CityId and a CategoryId, which are both also local storage variables that get set during the session before the user gets to the Posts page. So the steps are:
User logs in
Searches their city and chooses it - sets CityId local storage variable
Chooses their category - sets CategoryId as local storage variable
Hits View Posts
It takes them to the Posts page and runs the Posts Query Service, and I want them to see only the rows from the Posts collection that have the CityId and CategoryId they chose.

Can someone provide the javascript I need to add to the 'where' request parameter on the Posts query service so that it looks at the Local Storage Variables for CityId and CategoryId and returns only rows that match?

Thanks!


Simple Javascript question

Posted: Fri Jul 11, 2014 3:43 am
by Yurii Orishchuk

Hi Peter,

You can use following code:

pre

var CityId = localStorage.getItem("CityId");
var CategoryId = localStorage.getItem("CategoryId");

var whereObject = {"CityId": CityId, "CategoryId": CategoryId };

return JSON.stringify(whereObject);

/pre

Note: in this code:

1 i've use "CityId" as LSV name and field in DB name.
2 i've use "CategoryId" as LSV name and field in DB name.

Regards.


Simple Javascript question

Posted: Fri Jul 11, 2014 4:23 am
by Peter Viglietta

Worked perfectly, thanks Yurii!

I have a few other questions.. The query service runs on the Posts collection, that just has columns for Subject and Body, and then of course the CreatedAt and UpdatedAt. I have the response mapping the Subject column to a Label within a list item (with the dollar sign thing mapped to the top of the list item, so it creates the automatic looping effect and displays all the results). I also have the CreatedAt column mapped to a label within that list item. So the page just shows a list of Subject lines, with their created date/time. But it displays in time ascending order. Can I modify the query so that it returns it in time descending order?

Also, that CreatedAt value is date and time.. is there a way to make it display date only? I'll copy an example of a date/time directly from the DB in case that helps:

I want just
2014-07-11
instead of
2014-07-11 03:58:42.299


Simple Javascript question

Posted: Fri Jul 11, 2014 9:32 pm
by Alena Prykhodko

Hello Peter,

1) [quote:]Can I modify the query so that it returns it in time descending order [/quote]
Please take a look here http://devcenter.appery.io/documentat...

2) To the mapping of CreatedAt parameter to label add the next code:

pre return value.slice(0,10);/pre


Simple Javascript question

Posted: Sat Jul 12, 2014 12:15 am
by Peter Viglietta

Thanks Alena!


Simple Javascript question

Posted: Sun Jul 13, 2014 3:08 am
by Peter Viglietta

Hi Yurii, I have a similar page where I need query two columns using one local storage variable. The code below is wrong, because it's returning all rows where the local storage variable CurrentUserId is both the SentToId and the SentFromId. How can I write it so that it returns all rows where the CurrentUserId is either the SentToId or the SentFromId?

var CurrentUserId = localStorage.getItem("CurrentUserId");
var whereObject = {"SentToId": CurrentUserId, "SentFromId": CurrentUserId};
return JSON.stringify(whereObject);


Simple Javascript question

Posted: Sun Jul 13, 2014 6:36 pm
by Peter Viglietta

I want to do the a similar thing with how the subject of a post displays on a message board. I want the Subject to appear as only the first 20 characters, then '...'

Is there a way to add the 'dot dot dot' to this?

return value.slice(0,20);


Simple Javascript question

Posted: Mon Jul 14, 2014 2:59 am
by Yurii Orishchuk

Hi Peter,

Please use following code:

pre

return value.slice(0,20) + "...";

/pre

Regards.