0
I am new as Javascript programmer and I’m having a difficulty that maybe for some is no problem.
observe the HTML code well;
<tbody>
<tr v-for="bancodedado in filteredBancodedaos ">
<td>{{ bancodedado.name }}</td>
<td>{{ bancodedado.height }}</td>
<td>{{ bancodedado.mass }}</td>
<td>{{ bancodedado.eye_color }}</td>
<td>{{ bancodedado.gender }}</td>
<td>{{ bancodedado.hair_color }}</td>
</tr>
</tbody>
Now the Javascript code;
var app = new Vue({
el: '#app',
data: {
bancodedados: [],
MySearch:''
},
methods: {
},
created: function() {
var self = this;
self.$http.get('https://swapi.co/api/people/?format=json').then(function(response) {
self.bancodedados = response.body.results;
});
},
computed: {
filteredBancodedaos () {
return this.bancodedados.filter((bancodedado) => {
return bancodedado.name.match(this.MySearch);
})
}
}
});
What is the purpose of this code? is to filter by name
The code is working perfectly.
what I need to do is create a flow control in the code below that can be able to filter by name, height, mass, eye_color or by gender.
can be any flux control: if Else, for, switch case or any other.
computed: {
filteredBancodedaos () {
return this.bancodedados.filter((bancodedado) => {
return bancodedado.name.match(this.MySearch);
})
}
}
I have been able to evolve in this study due to some documentations found on the internet, but not everything I can find... I really need help.
That was my attempt;
computed: {
filteredBancodedaos () {
return this.bancodedados;
.filter((bancodedado) => {
return bancodedado.name.match(this.MySearch);
})
.filter((bancodedado) => {
return bancodedado.height.match(this.MySearch);
})
}
}
when I was unsuccessful :(
thanks for the support being unable to do, I made an update of my post, could you take a look please.
– wladyband
The way you implemented it will only return, if all fields give Match with the survey.. I’ll put a chunk of code q should work for your filter in my previous answer
– Vinicius Figueiredo Rodrigues