tariq
Posts: 0
Joined: Wed Nov 13, 2013 5:23 pm

Passing Many Variables to Database query service.

Hi,

I have a mobilecheckboxgroup, I wrote a script to collect Results from it and

create a string contain all choices separated by "," like this:

var choices="choice1,choice2,"

how can i parse choices var and pass values to database query??

I really appreciate any help you can provide.

tariq
Posts: 0
Joined: Wed Nov 13, 2013 5:23 pm

Passing Many Variables to Database query service.

I used the following script to collect results on click button search:

Appery("mobilecheckboxgroup_1").find("input:checked").each(function(){
var cat= $(this).val()+ ',' + localStorage.getItem('category');
localStorage.setItem('category',cat);
});
Qureryservice2.execute();

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Passing Many Variables to Database query service.

Hi,

Get an array from the string using the following code:prevar choicesArray = choices.split(",");/pre

tariq
Posts: 0
Joined: Wed Nov 13, 2013 5:23 pm

Passing Many Variables to Database query service.

Thanks Katya for your quick response.

I did the split and now i have an array of choices.

How can i make one database query for all choices at sametime.

for example:

choice1 (or) choice2 ....

like this maybe:

return '{"choice":"'+value[0]+'"^"value[1]"^"value[2]".....}';

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Passing Many Variables to Database query service.

There is another logic.

If return c[0] ... c[n], then only c[0] will be chosen, if this is not empty. It can't be empty because generated from a string. Please post an example of the data you need the function to return.

tariq
Posts: 0
Joined: Wed Nov 13, 2013 5:23 pm

Passing Many Variables to Database query service.

Thanks Katya i really appreciate your help :)

Basically, i have this script on search button to collect categories:

=========================================================
Appery("mobilecheckboxgroup_1").find("input:checked").each(function(){

Code: Select all

 var cat= $(this).val()+ ',' + localStorage.getItem('category'); 

 localStorage.setItem('category',cat); 

});

// to put categories in array instead of string:

var categoryArray = localStorage.getItem('category').split(",");

localStorage.setItem('category',categoryArray);

Qureryservice.execute();

==========================================================

Image

I created DB service Query and mapped 'category' -Local storage variables- into

"Where " in Request Tap.

Image

Now I want to Create JS Code to Query for categories maybe like this one:

===========================================================

// HEAE is my PROBLEM:

return {"category":{"$in": [+value+] }};

===========================================================

Thanks

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Passing Many Variables to Database query service.

Hello! If you have localStorage variable where you store records separated by comma, you have correct mapping but incorrect JS prereturn {"category":{"$in": [+value+] }};/pre but it should be prevar options = value.split(',');
var query = {"category": {$in: options }};
return JSON.stringify(query);/pre this way request to DB will return all records with "category" from the values list from localStorage variable.

tariq
Posts: 0
Joined: Wed Nov 13, 2013 5:23 pm

Passing Many Variables to Database query service.

Thanks Maryana, Everything Work Perfectly.

Return to “Issues”