I'm trying to filter my array with data in Vue.js. I do it in computed property. This is the test array:
{
"Animals": [
{
"date_time": "2011.08.31",
"animal_list": [
{
"animal_title": "Monkey"
},
{
"animal_title": "Giraffe"
}
]
},
{
"date_time": "2012.08.31",
"animal_list": [
{
"animal_title": "Raccoon"
},
{
"animal_title": "Giraffe"
}
]
}
]
}
And this is my filter function:
filteredData.filter(item =>
item.animal_list.some(
elem =>
elem.animal_title
.toLowerCase()
.indexOf(this.animalTitle.toLowerCase()) != -1
)
);
It seems good, but doesn't work. When I enter "Raccoon" in the form, it must return only second object, but it returns all objects.
Why does it happen? What am I doing wrong?
UPD: filteredData is an Array. filteredData = animalData.Animals
this.animalTitle
is an empty string when you run the filter. Put a breakpoint and see. – Jonathanthis.animalTitle
– Anurag Srivastava