Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Underscorejs _.where with wildcard

Have the following in an AngularJS controller:

$scope.initiatives = _.where($scope.initiatives, {i_status_id:'Open'});

It works fine to filter down the list based on a field if the property value is exactly 'Open'.

How do you use wildcard in the filter value so that it picks up 'Open - Pending' if I search for all the ones that contain 'Open'?

like image 708
AlanW Avatar asked Mar 24 '23 19:03

AlanW


1 Answers

You can use _.filter instead. Something like:

$scope.initiatives = _.filter($scope.initiatives, function(initiative){
    return initiative.i_status_id.indexOf('Open')>=0;
});
like image 188
Supr Avatar answered Apr 21 '23 09:04

Supr