How to Do .where Equals Anything

I use .where() a lot to select lists of things - contacts for example.

Often I am saying something like:

repeat contacts.data.where('age_range', input_age_range.value, "==")

So this will show me the contacts in the age range selected by input_age_range.

However, if input_age_range has nothing selected, then I want to show contacts of all age ranges… but that doesn’t work this .where type of function.

Is there an easy way around what I am looking to do…?

Best wishes,
Antony.

1 Like

Hi Antony,
The equals operator always expects a value. An empty string (what an empty inputs returns) is also a value.

You can do this like:

input_age_range.value ? contacts.data.where(`age_range`, input_age_range.value, "==") : contacts.data

But it’s much better to filter your data source directly instead of doing it for the repeat.

Thanks Teodor!

Why do you say this?

I have 200 lookups and I read them once and store them in the local storage to save database access, so it seems much easier to filter them with .where()...

I'm a big .where() fan.

I remember Patrick telling me there is another function I can use too... Is that .filter ()?

Not being secure storage would be my number one concern.

But it’s not secure data… just values like “Card Payment”, “Male”, “Female”, “Over 60”, dull stuff like that! :slight_smile:

Oh. Then it is ok. If you are storing labels and things like that. As long as it’s not data bound to changing often.