Page 1 of 1

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

Posted: Fri Oct 24, 2014 11:32 am
by Takis

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


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

Posted: Fri Oct 24, 2014 12:21 pm
by Evgene Karachevtsev

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


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

Posted: Fri Oct 24, 2014 4:00 pm
by Takis

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


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

Posted: Fri Oct 24, 2014 4:00 pm
by Takis

In the JS I mean


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

Posted: Mon Oct 27, 2014 8:09 am
by Evgene Karachevtsev

Hello Panagiotis,

Thank you for the update!


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

Posted: Mon Jul 20, 2020 1:17 pm
by Takis

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