I have a vaadin-grid and I want to show a list of data from firebase database. I know that based from the docs, this structure is ugly and I should create another subtree for this but and just want to make a proof of concept. So here is the code:
ready() {
var items = [];
if (this.locationKey) {
var territoryRef = firebase.database().ref('Territories').child(this.locationKey);
var householdRef = firebase.database().ref('Households');
var contactsRef = firebase.database().ref('Contacts');
territoryRef.once('value').then((terrSnap) => {
terrSnap.forEach((terrChildSnap) => {
var territoryName = terrChildSnap.val().name;
var territoryKey = terrChildSnap.key;
householdRef.child(territoryKey).once('value').then((householdSnap) => {
if (householdSnap.val()) {
householdSnap.forEach((householdChildSnap) => {
var household = householdChildSnap.val();
var householdName = household.name;
var householdKey = householdChildSnap.key;
contactsRef.child(householdKey).once('value').then((contactsSnap) => {
if (contactsSnap.val()) {
contactsSnap.forEach((contactsChildSnap) => {
var contacts = contactsChildSnap.val();
var contactsName = contacts.name;
var contactsKey = contactsChildSnap.key;
items.push({ territory: territoryName, name: contactsName, household: householdName, nationality: contacts.nationality, language: contacts.language || "" });
})
}
})
})
}
})
})
this.items = items;
}).catch((err) => {
console.error(err)
});
}
}
And I just put the items array in the grid
<vaadin-grid id="grid" aria-label="Contacts Summary" items="[[items]]">
<vaadin-grid-column width="50px" flex-grow="0">
<template class="header">#</template>
<template>[[index]]</template>
</vaadin-grid-column>...
The grid loads fine but it doesn't show the data. I can confirm though that that this.items is populated. Though not being shown in the grid. Please let me know what I'm doing wrong. Thank you
setmethod:this.set('items', items).