在 Angular Tree 中,我正在从数据库中检索数据,但树格式并不符合预期。 下面是浏览器树视图。
根据上图,在 Country Node 中,我正在获取 Children Item 中的每个元素,但我只想要不同的 Item,即单个 India 项目和单个 Australia 项目。
下面是我的组件代码:
GetTreeValue(): void {
debugger
this._StudentService.getRegionList(1,2).subscribe(data=>{
this.RegionList=data;
let tree_data:any=[];
let country:any=[];
let state:any=[];
let district:any=[];
let region:any=[];
data.forEach(elem=>{
let country_node:any={
name:elem.Country
}
country.push(country_node);
let state_node:any={
name:elem.State
}
state.push(state_node);
let district_node:any={
name:elem.District
}
district.push(district_node);
let region_node:any={
name:elem.Region
}
region.push(region_node);
});
let root_obj:any={
name:'data',
children:[
{
name: 'Country',
children: country
},
{
name: 'State' ,
children:state
},
{
name: 'District' ,
children: district
},
{ name: 'Region' ,
children: region
}]
};
TREE_DATA.push(root_obj);
this.dataSource.data =TREE_DATA;
});
}