Skip to content

Instantly share code, notes, and snippets.

@cargix1
Last active September 11, 2015 22:59
Show Gist options
  • Save cargix1/e7f04214915383c9e198 to your computer and use it in GitHub Desktop.
Save cargix1/e7f04214915383c9e198 to your computer and use it in GitHub Desktop.
Filter for select fields using Vue.js. You can call
# 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