Suppose that I have the following data in Firebase Database
{
"carros" : {
"-LAy3Qqrvq_sIhyLJQED" : {
"añoFabricacion" : 1932,
"marca" : "toyota",
"nombre" : "nombre1"
},
"-LAy3r-Gm_NWW9_VkGR3" : {
"añoFabricacion" : 1931,
"marca" : "audi",
"nombre" : "nombre2"
},
"-LAy3v9L2wecTDZqpok9" : {
"añoFabricacion" : 1934,
"marca" : "toyota",
"nombre" : "nombre3"
}
}
}
I want to print in console the attribute "nombre" of the objects whose "marca" attribute is equals to "toyota". I wrote a controller code as follows:
import Controller from '@ember/controller';
export default Controller.extend({
actions: {
mostrar() {
this.get('store').query('carro', {
filter: {
marca: 'toyota'
}
}).then(function(carros) {
carros.forEach(function(carro) {
console.log(carro.get('nombre'));
})
});
}
}
});
And the corresponding code for the model "carro.js" is:
import DS from 'ember-data';
export default DS.Model.extend({
nombre: DS.attr('string'),
marca: DS.attr('string'),
añoFabricacion: DS.attr('number')
});
The problem is that I am obtaining the following output:
nombre1
nombre2
nombre3
But the correct output must be:
nombre1
nombre3
Why I am getting this error?
Aucun commentaire:
Enregistrer un commentaire