I want to make a dynamic filter method, but don't know how to include conditions dynamically.
Example
var do_test_1 = true,
do_test_2 = false,
do_test_3 = true;
Now there are three tests:
if (foo == bar) // test 1
if (john == doe) // test 2
if (jane == doe) // test 3
Now I want to build a dynamic if clause, based on the do_test vars.
Real use case
I have a list of tasks and want to filter them:
- If the "assigned to me" filter is active, it should return only the the tasks that are assigned to me.
- If the "high priority" filter and the "assigned to me" filter is active, it should return only the tasks that are assigned to me and have a high priority.
- ... and so on ...
I played around with the filter method, but I only get it working with an OR logic (show tasks that are assigned to me or have a high priority):
var $show = $tasks.filter(function(index, task) {
var $task = $(task);
return ((task.data('assigned') && filters['mytasks']) || (task.data('priority') == 3 && filters['priority']))
});