Last active
September 11, 2015 22:59
-
-
Save cargix1/e7f04214915383c9e198 to your computer and use it in GitHub Desktop.
Filter for select fields using Vue.js. You can call
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
# Add the following to your app.js file. | |
Vue.filter('extract', function (values, option_value, option_label) { | |
var response = []; | |
values.forEach(function (value) { | |
response.push({ | |
text: value[option_label], | |
value: value[option_value] | |
}); | |
}); | |
return response; | |
}); | |
# Then you can use the filter like this: | |
<select v-model="selectedOption" options="countries | extract 'country_code' 'country_name'"></select> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment