Deki
Posts: 0
Joined: Tue Apr 15, 2014 4:53 pm

How to get extract an array from database in JavaScript

Hi, I have an array field called calendarDays that I would like to extract and use in JavaScript, but I'm not sure how to do it. On success callback I would like to extract the value from the database which is an array of strings like this ["{2014-05-05}","{2014-05-23}"] . Also, I would need to have multiple conditions in WHERE clause. I need to specify name and monthYear. Can you show me how to do that? Please review the database picture I attached as well...Thanks.

I have a query service called "query"

On Click event handler I have this code
pre
query.execute({
where:{"name":"jon"}, //i also need to add monthYear
success:function(data){
alert("success!!!"+value); //i want to get calendarDays array
},
error:function ( jqXHR, textStatus, errorThrown ) {
alert("error!!!");
}
});
/pre Image

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

How to get extract an array from database in JavaScript

Hello Deki,

Success function which print all values of field "calendarDays":
code

for (i = 0; i < data&#46;length; i++){
for (j = 0; j < data&#46;calendarDays&#46;length; j++){
alert(data&#46;budnie[j]);
}
} /code

Deki
Posts: 0
Joined: Tue Apr 15, 2014 4:53 pm

How to get extract an array from database in JavaScript

Hi Evgene,

Just to correct the code above, you need to replace budnie[j] with calendarDays[j]. So, that part works. However, how can I also I put in a userSessionToken as one of the WHERE parameters? The reason is because I have different users, so I want to make sure and get the relevant data for each user. I would also want to include one more parameter in the WHERE clause, monthYear.

Thanks

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

How to get extract an array from database in JavaScript

We have a greate example that can help you to work out how to organize showing users their data only: http://docs.appery.io/tutorials/build...
You need to use acl and session token for your goals.

Documentation about using query: http://docs.appery.io/documentation/b...

Return to “Issues”