Page 1 of 1

How to reference database columns with javascript

Posted: Sat Oct 25, 2014 6:58 pm
by Bobby Newland

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


How to reference database columns with javascript

Posted: Sat Oct 25, 2014 7:53 pm
by Bruce Stuart

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 ...


How to reference database columns with javascript

Posted: Sat Oct 25, 2014 8:03 pm
by Bobby Newland

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?


How to reference database columns with javascript

Posted: Sat Oct 25, 2014 8:47 pm
by Bruce Stuart

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


How to reference database columns with javascript

Posted: Sat Oct 25, 2014 8:49 pm
by Bruce Stuart

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


How to reference database columns with javascript

Posted: Sat Oct 25, 2014 9:42 pm
by Alena Prykhodko

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...