Answer the question
In order to leave comments, you need to log in
How can the code be improved when searching for multiple fields?
I know that I made a crutch, but I made it approximately how the code would work and showed how I want to do it.
That is, what I want to get from this, if it is not clear, that he searches in the last name, first name, patronymic, phone and email columns for the value that is indicated in the search.
My poor implementation looks like this
/src/views/AppTest.vue:278
this.items
.filter(item => {
let search = this.search.toLowerCase();
let name = item.name.toLowerCase().includes(search);
let last_name = item.last_name.toLowerCase().includes(search);
let patronymic = item.patronymic.toLowerCase().includes(search);
let phone = item.phone.toLowerCase().includes(search);
let email = item.email.toLowerCase().includes(search);
//Если что-то нашел у поле, то это он возвращает
if (name) return name;
if (last_name) return last_name;
if (patronymic) return patronymic;
if (email) return email;
if (phone) return phone;
})
Answer the question
In order to leave comments, you need to log in
An example from the vue documentation: grid with search.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question