Forked from VictorQueiroz/angularjs-join-filter.js
Last active
August 29, 2015 14:02
-
-
Save darlanalves/5b0865b7e3c8e3b00b67 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Exemplo: | |
* var users = [ | |
* {name: 'Victor Queiroz'}, | |
* {name: 'João Bosco'}, | |
* {name: 'Ruan Jordão'} | |
* ]; | |
* | |
* Aplicando o filtro: | |
* {{ users | pluck:'name' | join:', ' }} | |
* | |
* Retorno: | |
* Victor Queiroz, João Bosco, Ruan Jordão | |
* | |
* Dependências: | |
* - VanillaJS | |
*/ | |
angular.module('filters', []) | |
.filter('join', function() { | |
return function(list, token) { | |
return (list||[]).join(token); | |
} | |
} | |
.filter('pluck', function() { | |
function pluck(objects, property) { | |
if (!(objects && property && angular.isArray(objects))) return []; | |
property = String(property); | |
return objects.map(function(object) { | |
// just in case | |
object = Object(object); | |
if (object.hasOwnProperty(property)) { | |
return object[property]; | |
} | |
return ''; | |
}); | |
} | |
return function(objects, property) { | |
return pluck(objects, property); | |
} | |
}); | |
}); |
@darlanalves, @VictorQueiroz,
extended version of pluck filter https://gist.github.com/padaril/c0647a6b3d59d64c79d0
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So fucking much better, congratulations! And thank you!