I've got a really complex problem.
I've got this dynamic array , that might include 0 to -> n values :
This is an example :
var array =[2,3,8];
this is the second example :
var array =[2,3,8,15,25];
Now, i need to execute this function( gently given by a stakoverflower), but i don't know how to consider each values each times; it is a static function for now, that is working well :
var filteredList = $filter('filter')($scope.footballers, function (i) {
return (i.identifiant === 2 || i.identifiant === 3 || i.identifiant === 8);
});
But look, it works for the first array example, but not for the second array example.
If i want to treat the second array, i need to type this :
var filteredList = $filter('filter')($scope.footballers, function (i) {
return (i.identifiant === 2 || i.identifiant === 3 || i.identifiant === 8 || i.identifiant === 15 || i.identifiant === 25);
});
My question is : How could i add a for loop inside the $filter function, to be able to treat the second array or whatever long the array is ?
Thank you a lot if you have an idea. The loop would then automatically type i.identifiant === array[0], i.identifiant === array[1] and so on !
I've never encoutered this case, and i really don't know how to return a dynamic long array !
This would also work for the first example :
var filteredList = $filter('filter')($scope.footballers, function (i) {
return (i.identifiant === array[0] || i.identifiant === array[1] || i.identifiant === array[2]);
});
But how could i do if my array contains 12 values ??? I need a loop, but i dont know how to do at all !
The loop would then be supposed to type "i.identifiant === array[x]"
Ooops , i forgot, my goal is to display a list of footballers whoses identifiers are presents inside the array "array", using angularjs. Into a drag and drop application. That is why i filter, there are a large amount of identifiers inside $scope.footballers, but i only wanna keep a few, the ones presents inside the array ! The problem is that the array "array" may contain 2 values as well as 25 values .
I was thinking about a loop with an eval() inside or at the end?
See Question&Answers more detail:
os