Bobby Newland
Posts: 0
Joined: Wed Jul 23, 2014 12:29 pm

How to reference database columns with javascript

Hi I was looking but was unable to find an answer to my question. I'm trying to find out how I can reference database columns with javascript. For instance I have user favorites set up and when a user adds a favorite I want to change the button from add to remove with jQuery. or if the user has not saved any favorites i can display a message saying "No favorites added yet" . So i could possibly write some code saying if this item ID exists hide this button and show this button .. or if no records exist in this collection show this message.

Thanks in advance

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

How to reference database columns with javascript

Bobby, if your writing code in JavaScript inisde of a data service event ... Success ... The "results" are available in a parameter to the success function called 'data'. You can access the columns of the results by treating the resits as an array ... So data[0] is the first element and if you had a column called favorite you can access it by data[0].favorite ... Much like you would deal with an array.

Not sure if that help ...

Bobby Newland
Posts: 0
Joined: Wed Jul 23, 2014 12:29 pm

How to reference database columns with javascript

Hey Bruce,

Thanks for the quick reply. Just so I can make sure I'm clear I can create a success event and write my code there.. also you said I can access the database records as an array meaning that each row will be an index and then I can access each column for that particular index?

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

How to reference database columns with javascript

Bobby, in your data service to get the data .. Just click the Dropdown for 'success' and then click 'run JavaScript ... There you can write custom code to store local cats, etc and change controls on your UI ... You do the change control values with the Appery() function ...and yes your results come into a data element you can use in your Javascript called data.

You can access columns like this data[row number 0 to n ].columnname

So data[0].firstnamefor row 1 , element - column name d 'firstname'

Read up on Java script arrays ... Look at the w3schools sight for more

Best
Bruce

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

How to reference database columns with javascript

And sorry for the typo's it's not local cats it's local vars

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

How to reference database columns with javascript

Hello,

You can create request on jquery or with js
You will need to point 'X-Appery-Database-Id' with database ID, if you want to use "Users", "Devices" or "Files" then you will need to use token "X-Appery-Session-Token"
Please read here http://devcenter.appery.io/documentat...

Return to “Issues”