Takis
Posts: 0
Joined: Wed Oct 22, 2014 5:10 pm

Read array of local storage and parse it to use it in DB query where clause

Hi

I have the below JS for a DB service where clause

return '{"Type":"' + localStorage.getItem("lclStg_par1") + '"}';

where lclStg_par1 is a local storage parameter, where I store an array of dynamically created check boxes.
If I have one value in lclStg_par1, like Food, all works fine.
If in the lclStg_par1, I have Food,Drink, query where does not work.

I would like to have a code to parse the lclStg_par1 array and construct the proper where clause, so I can return all records from DB that contains Food and Drink.

Thanks a lot.!

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

Read array of local storage and parse it to use it in DB query where clause

Panagiotis ,

You should have the following condition:
pre{ "$or": [ { "Type": "Food" }, { "Type": "Drink" } ] };/pre
if your variable lclStg_par1 equals "Food,Drink, then your code to get the desired condition will be the following:
prevar lsData = localStorage.getItem("lclStgpar1"),
lsDataArr = lsData.split(','),
conditions = .map( lsDataArr, function( value ){
return '{"Type":' + '"' + value + '"}';
});

return '{ "$or": [ ' + conditions.join(',') + ' ] }';/pre

Takis
Posts: 0
Joined: Wed Oct 22, 2014 5:10 pm

Read array of local storage and parse it to use it in DB query where clause

-- the dot in ".map" is correct?
the comma in two first lines are correct?

I have issues with the code and I want to use it inside the mapping of the query service Image

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

Read array of local storage and parse it to use it in DB query where clause

Hello Panagiotis,

Thank you for the update!

Takis
Posts: 0
Joined: Wed Oct 22, 2014 5:10 pm

Read array of local storage and parse it to use it in DB query where clause

; } } text = ""{ \""$or\"": ["" + text + ""] }""; return text; ======================== this code goes to the JS button of the Service of the ""where"" value. NO mapping is required."

Return to “Issues”