Created
June 3, 2014 22:12
-
-
Save VictorQueiroz/573d5bc5d595b6ab57eb to your computer and use it in GitHub Desktop.
An amazing AngularJS filter, based on Jekyll join filter.
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
/* | |
* Esta função retira apenas as chaves de nome igual a @index de | |
* todos os objetos dentro de um array, coloca apenas os valores | |
* das respectivas chaves nas respectivas ordens, dentro de um | |
* array e logo depois faz um join(), retornando apenas | |
* uma string, separada por @token. | |
* Exemplo: | |
* var users = [ | |
* {name: 'Victor Queiroz'}, | |
* {name: 'João Bosco'}, | |
* {name: 'Ruan Jordão'} | |
* ]; | |
* | |
* Aplicando o filtro: | |
* {{ users | join:',':'name' }} | |
* | |
* Retorno: | |
* Victor Queiroz, João Bosco, Ruan Jordão | |
* | |
* Dependências: | |
* - underscore.js | |
*/ | |
angular.module('joinFilter', []).filter('join', function() { | |
return function (input, token, index) { | |
return _.pluck(input, index).join(token); | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@darlanalves, @VictorQueiroz,
extended version of pluck filter https://gist.github.com/padaril/c0647a6b3d59d64c79d0