正在工作的有角度的消防站项目,想要创建以下结果:
[{
label: 'Item 1.2',
queries: [
{
label: 'Item 1.2.1',
},
{
label: 'Item 1.2.2',
}
}]
尝试:
//获取收集数据
this.blockCollection = this.afs.collection<Block>
('blocks', ref => ref.orderBy('name', 'asc'));
this.blocks = this.blockCollection.snapshotChanges().pipe(
map(actions => actions.map(a => {
const data = a.payload.doc.data() as Block;
data.id = a.payload.doc.id;
return data;
}))
);
const that = this;
this.blocks.subscribe({
next(x) {
that.showList(x);
},
error(err) {
this.msgType = 'danger';
this.msg = 'Error! while getting records.';
}
});
// Creating list
private showList(list) {
this.block_list = [];
list.forEach(t => {
const item = {
label: t.name,
};
if (t.queries) {
const sub = [];
t.queries.forEach(q => {
const sitem = {
label: q.name,
};
sub.push(item);
});
item['items'] = sub;
}
this.block_list.push(item);
});
}