I have the following view which should work the filter with a computed property but I can't get it to work for me, it shows me the following error
vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in render: "TypeError: platform.work is not a function"
The view is as follows:
<template>
<input type="text" v-model="filtrarTarima">
<div v-for="(tarima, id) in filtrar" :key="id">
{{ tarima.tarima}}
</div>
</template>
<script>
export default {
data() {
return {
filtrarTarima: '',
tarimas: [
{
id: 1,
tarima: 19347,
trabajo: 195288,
parte: "A006287",
cantidad: 237,
maquina: "MINILINE 618",
ubicacion: "ALM05"
},
{
id: 2,
tarima: 19348,
trabajo: 195289,
parte: "A006288",
cantidad: 236,
maquina: "MINILINE 618",
ubicacion: "ALM05"
}
],
}
},
computed: {
filtrar: function() {
return this.tarimas.filter((tarima) => tarima.trabajo.includes(this.filtrarTarima));
}
}
}
</script>
But the filter does not work, could you help me please
You are using the method
includes()
which will:For this case, some of the keys of your objects do not store text strings, therefore the numerical values are not iterable.
For example:
Results:
Whereas if you declare that same numeric value in quotes like this:
Results:
So you could have as options:
USE ANOTHER PASSWORD TO FILTER
You can take any key that stores a string to filter like this:
CHANGE THE ORIGINAL VALUE
That is, those keys that have values that are originally numeric, you can modify them by placing them in quotes and thus make them iterable; so that the method
includes()
can carry out its work on said element.Even if the value associated with the key that is originally declared as a number is enclosed in quotes, it does not matter if the argument passed to the method
includes()
arrives with its original format, it will still work:REFERENCES
includes()
As you were told, there is no such thing as
Number.prototype.includes
. It is handled by casting to String:@gbianchi note that the input allows filtering. If you have many pallets this is useful
I recommend that the computed properties better describe what they mean (eg 'FilteredStacks').
A verb like
filter
is more intuitive than it is a method. this is just a comment