Skip to content

Instantly share code, notes, and snippets.

@mtermoul

mtermoul/home-view-methods.js Secret

Created Apr 3, 2019
Embed
What would you like to do?
col-admin/src/views/Home.vue
...
methods: {
filterByTextContains (list, fieldName, fieldValue) {
const re = new RegExp(fieldValue, 'i')
return this.filterByRegExp(list, fieldName, fieldValue, re)
},
filterByTextStartsWith (list, fieldName, fieldValue) {
const re = new RegExp('^' + fieldValue, 'i')
return this.filterByRegExp(list, fieldName, fieldValue, re)
},
filterByRegExp(list, fieldName, fieldValue, regExp) {
return list.filter(item => {
if(item[fieldName] !== undefined) {
return regExp.test(item[fieldName])
} else {
return true
}
})
},
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.