I want to show or hide a div based on a value being in that list. Server-side I would use IN in the query but I just want a simple solution to do it client-slide.
I can’t find the necessary option within the attributes.
Sorry to interrupt here, but I have a question about contains.
Let’s say I have [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
Array.contains(‘1’) retrieves 1,10,11 or I’m wrong?
That’s a good question. I had assumed it wasn’t treating the array as a single string and looking for a value within it but, instead, split it into virtual records and did a search on those records for the value equalling it. But I now wonder if I’m wrong.
I’m hoping I’m not, though, as that’s how it should really work.
Hey Jon,
I apologize brother…
The Json field coming from a database looks like “15,16,18”.
That means that the first item is "15 , the second is 16 and the last item is 18"
In my test before I answer to you, I just searched (randomly) for the middle one and it was it was correct… But if I search for the first or the last item it will not match… Because "15 is not equal to 15
So, my workaround on this is to replace first the double quotes with '' and then the rest:
yourJsonField.replace(’"’, ‘’).split(’,’).contains(theSearchValue)
Be aware, you always search for strings… So, if you check for 15 you have to say contains(15.toString())
And we don’t have problem on retrieving part of an item in an array… (1 instead of 11)
It will match the exact value with the values between the commas