jeudi 28 avril 2016

If condition that pushes values that contain/match a string

I have a nicely functioning full calendar script. I have some filters for it, which basically have the following form:

$("input[name='event_filter_select']:checked").each(function () {
    // I specified data-type attribute in HTML checkboxes to differentiate
    // between risks and tags.
    // Saving each type separately
    if ($(this).data('type') == 'risk') {
        risks.push($(this).val());
    } else if ($(this).data('type') == 'tag') {
        tagss.push($(this).val());
    }
});

However the else if statement should check if the checked value 'tag' is contained within the result set, not be the only value of the result set (as implied by the ==).

Now I can only filter results that have the checked tag-value only. But i want to filter those, which have the tag-value amongst many others.

I figure this is to be done with match(/'tag'/) but i cannot figure out for the life of me how to put that into an if-statement.

Would be really glad if someone could lead me in the right direction.

Aucun commentaire:

Enregistrer un commentaire